利用javabean轻松实现对数据库的连接、查询以及增删改
<%@ page contentType="text/html" import="operate_db.*,java.sql.*" %>
<jsp:useBean id="querybean" scope="request" class="operate_db.QueryBean" />
<%
String prm1,prm2,prm3;
ResultSet rst=null;
prm1 = ...;
prm2 = ...;
prm3 = ...;
querybean.setConnection("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:数据源名","sa","");
try{
String[] param = {prm1,prm2,prm3};
/*设置select语句*/
querybean.setQuerystatement("Select * from table where field1 = ? and field2=? and field3=?");
querybean.setParam(param);
rst=querybean.getResult();
}catch(Exception e){System.out.println(e); }
while (rst.next()){
%><%=rst.getString(1)%>
<%}%>