熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

在JSP中訪問各種數據庫[3]

2013-11-15 12:20:06  來源: JSP教程 

  jsp連接Access數據庫

<%@page import=javasql*
import =javautil*
import =javaio*
import=javatext*
contentType=text/html; charset=gb
buffer=kb
%><%! int allim_count;
String odbcQuery;
Connection odbcconn;
Statement odbcstmt;
ResultSet odbcrs;
String usernametitlecontentworkemailurltimedate;
String datetime;
%>
<%
try{
ClassforName(sunjdbcodbcJdbcOdbcDriver);
}catch (ClassNotFoundException e)
{ outprint (驅動程序不存在);
}
try{
odbcconn = DriverManagergetConnection(jdbc:odbc:db);
odbcstmt = odbcconncreateStatement();
odbcQuery=Select * From book where datetime> Order By datetime DESC;
odbcrs=odbcstmtexecuteQuery(odbcQuery);
int i=;
while (i<) odbcrsnext();
while (odbcrsnext())
{
//*/////////////////////////顯示數據庫的內容用於調試程序是用//
int ii;
try{
try{
for (ii=;;ii++)
outprint (<br>Cloumn +ii+ is: +odbcrsgetString(ii));
}catch (NullPointerException e) {
outprint (有空的指針);
}
}catch (SQLException e){
}
}
odbcrsclose();
odbcstmtclose();
odbcconnclose();
}catch (SQLException e)
{ outprint (e);
}
%>

[]  []  []  


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20744.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.