javabean:
package org.zhou;
import java.sql.*;
public class Accessbean{
String db;
String sql;
ResultSet rs;
String tag;
public Accessbean()
{
}
public void setsqlStr(String strsql)
{
sql=strsql;
}
public void dbcon()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e)
{
}
try{
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:/db1.mdb";
Connection conn = DriverManager.getConnection(url);
PreparedStatement stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
if (rs!=null)
{
tag="ok";
}
else
{
tag="false";
}
}catch(Exception e)
{
}
}
public ResultSet getrs()
{
return rs;
}
public String gettag()
{
return tag;
}
}
/
调用页面为:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="conn" scope="page" class="org.zhou.Accessbean"/>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
conn.setsqlStr("select Pwd from UserInfo");
conn.dbcon();
out.print(conn.gettag());
ResultSet rs=conn.getrs();
while(rs.next())
{
out.println(rs.getString("Pwd"));
}
%>
</body>
</html>
没什么太多的技术含量只是希望更多的人能走捷径