利用javabean轻松实现对数据库的连接、查询以及增删改
2008-01-05 10:27:10 来源:WEB开发网核心提示:<%@ page contentType="text/Html" import="operate_db.*,Java.sql.*" %> <jsp:useBean id="querybean" scope="request"
<%@ 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)%>
<%}%>
更多精彩
赞助商链接