发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page language="java" import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>java007 JDBC</TITLE>
</HEAD>
<BODY>
<%
Connection con = null;
try
{
//连接数据库的反射
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String Conn ;
//数据库的实际地址
Conn = request.getSession().getServletContext().getRealPath("/") + "study\\study.mdb";
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=" + Conn;
//打开数据库连接
con = DriverManager.getConnection(url,"","");
//建立一个类似.Net的Command
Statement stmt = con.createStatement();
//执行SQL命令返回数据集
ResultSet rs = stmt.executeQuery("select * from SkyOprLog");
//循环读取数据
while(rs.next())
{
out.println(rs.getString("UserName"));
out.println("<br>");
}
}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(Exception e){}
}
%>
</BODY>
</HTML>
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。