; ; ; System.err.println(e.getMessage());
; }
return conn;
; }
;;
;;
; ; ;;
;//关闭数据库连接
; public void close()
; {
try{
; //rs.close();
; //stmt.close();
; conn.close();;
}catch(SQLException sqlexception){
; sqlexception.printStackTrace();
}
; }
}
调用方法如下:
复制内容到剪贴板代码:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@ page contentType="text/html; charset=gb2312" language="java";
import="java.sql.*" ;%>
<jsp:useBean id="DBConn" scope="page" class="conn.DBConnAccess"/>
<%;
; //连接Access 数据库
; String dbpath="data/test.mdb" ; ; ; ; ;//数据库的路径,请自行修改
; Connection conn=DBConn.getConnToAccess(application.getRealPath(dbpath));
; Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from username order by id";
; //String sql1="insert into username (uid,pwd) values('wsp','wsp')";
; //stmt.executeUpdate(sql1);
; ResultSet rs=stmt.executeQuery(sql);;
; while(rs.next()){
; out.print("用户名:");
; out.print(rs.getString("uid")+" 密码:");
; out.println(rs.getString("pwd")+"<br>");
; }
; DBConn.close();
%>
标签: