jsp+access直连不配数据源求出错求解

test代码如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>

<%
//连接Access 数据库
String dbpath="ceshi.mdb"; //数据库的路径,请自行修改
//String s=;
//String c=b.replaceAll("/", "\\");
Connection conn=DBConn.getConnectionToAccess(application.getRealPath(dbpath));
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql="select * from test";
// 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")+"
");
}
DBConn.close();
%>
DBConnAccess.java代码如下
package DB; //导入包

import java.sql.*; //导入数据库操作的类

public class DBConnAccess
{private String driver;
private StringBuffer accessURL;
private String accessFilePath;
private String accessFileName;
private Connection conn;
public DBConnAccess()
{driver="sun.jdbc.odbc.JdbcOdbcDriver";
accessURL=new StringBuffer("jdbc:odbc:driver= {Microsoft Access Driver (*.mdb)};DBQ=");
//setAccessFilePath("");
//setAccessFileName("");
conn = null;}
public Connection getConnectionToAccess(String s)
throws SQLException, ClassNotFoundException
{accessURL.append(s);
Class.forName(driver);
conn = DriverManager.getConnection(accessURL.toString());
return conn;
}
public void close()
{
try
{
conn.close();
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}

}}![图片说明](https://img-ask.csdn.net/upload/201506/19/1434697361_636762.png)图片说明

查看全部
yx1010709414
yx1010709414
2015/06/19 07:06
  • java
  • 点赞
  • 收藏
  • 回答
    私信

0个回复