一.建立數(shù)據(jù)庫(kù)
?。?建立jcc.mdb數(shù)據(jù)庫(kù)及user表
?。?添加測(cè)試數(shù)據(jù)
二.在<%wwwroot%>/下,新建Access數(shù)據(jù)庫(kù)連接文件Select.jsp
Select.jsp源碼如下:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
out.print(e);
}
try{
String strDirPath=application.getRealPath(request.getRequestURI());
strDirPath=strDirPath.substring(0,strDirPath.lastIndexOf('\\'))+"\\";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+strDirPath+"jcc.mdb";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM user");
out.println("User-list"+"<br>");
while(rs.next()){
out.print(rs.getString(1)+" ");
out.print(rs.getString(2)+"<br>");
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex){
out.print(ex);
}
%>
</body>
</html>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。