AJAX for Java简单表数据查询实例
|
JavaBean数据读取方法
import joyistar.eip.bs.*;
import joyistar.eip.vo.*;
import java.sql.*;
public class Simple extends BusinessObjectBean {
String drivers = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=database/demo.mdb";
String tablename = "product";
String username = "";
String password = "";
public Simple() {
}
public joyistar.eip.vo.XmlDataSet query_XML(joyistar.eip.vo.XmlDataSet xmlDataSet) throws Exception {
Connection conn = null;
String sql = "";
ResultSet rs = null;
Statement stmt = null;
try{
System.setProperty("jdbc.drivers", drivers);
conn = DriverManager.getConnection(url, username, password);
sql = "select * from " + tablename;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
rs.last();
xmlDataSet.setRecordCount(rs.getRow());
xmlDataSet.fillFields(rs);
xmlDataSet.fillData(rs);
}
catch(Exception e) {
xmlDataSet.error = e.getMessage();
e.printStackTrace();
}
finally {
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();
}
return xmlDataSet;
} |
|
JSP数据读取使用方法
<%@ page contentType="text/xml; charset=utf-8" %>
<%@ page import="joyistar.eip.vo.*" %>
<%@ page import="java.sql.*" %>
<%
String drivers = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=database/demo.mdb";
String tablename = "product";
String username = "";
String password = "";
Connection conn = null;
String sql = "";
ResultSet rs = null;
Statement stmt = null;
XmlDataSet xmlDataSet = new XmlRequest();
try{
xmlDataSet.open(request);
System.setProperty("jdbc.drivers", drivers);
conn = DriverManager.getConnection(url, username, password);
sql = "select * from " + tablename;
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(sql);
rs.last();
xmlDataSet.setRecordCount(rs.getRow());
xmlDataSet.fillFields(rs);
xmlDataSet.fillData(rs);
out.println(xmlDataSet.getXml());
out.flush();
}
catch(Exception e) {
xmlDataSet.error = e.getMessage();
out.println(xmlDataSet.getXml());
out.flush();
e.printStackTrace();
}
finally {
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();
}
%> |
|
Param param1 = xmlDataSet.getParam("SALE_ID");
if(param1!=null) {
sql += " where SALE_ID="+param1.value;
} |