jsp连接access问题

LingXX0103 2012-02-02 04:01:12
javabean代码:

package db;

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

public class DBConnAccess { //构造方法,初始化
private Connection conn; //连接对象
private Statement stmt; //语句对象
private ResultSet rs; //结果集对象
private String accessdriver; //保存Access驱动程序字符串
private String accessURL; //保存Access连接字符串
public DBConnAccess(){
//Access驱动程序
accessdriver = "sun.jdbc.odbc.JdbcOdbcDriver";
//连接字符串
accessURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=d:/shop.mdb";
conn = null;
}
public Connection getConnToAccess(String dbpath){
try{
accessURL = accessURL + dbpath;
Class.forName(accessdriver);
conn = DriverManager.getConnection(accessURL);
}catch(Exception e){
System.out.println("操作数据库出错,请仔细检查");
System.err.println(e.getMessage());
}
return conn;
}



//关闭数据库连接
public void close(){
try{
//rs.close();
//stmt.close();
conn.close();
}catch(SQLException sqlexception){
sqlexception.printStackTrace();
}
}
}



jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import ="db.DBConnAccess" %>
<jsp:useBean id="DBConn" scope="page" class="db.DBConnAccess"/>
<%
//连接Accesss数据库
String dbpath = "d:/shop.mdb"; //
Connection conn = DBConn.getConnToAccess(application.getRealPath(dbpath));
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql = "select * from USER order by uid";

ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
out.print("用户名:");
out.print(rs.getString("uid") + " 密码:");
out.print(rs.getString("pwd") + "<br>");
}
DBConn.close();
%>

错误信息:
org.apache.jasper.JasperException: An exception occurred processing JSP page /view/checkInput.jsp at line 9

6: //连接Accesss数据库
7: String dbpath = "d:/shop.mdb"; //
8: Connection conn = DBConn.getConnToAccess(application.getRealPath(dbpath));
9: Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
10: String sql = "select * from USER order by uid";
11:
12: ResultSet rs = stmt.executeQuery(sql);


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


原因

java.lang.NullPointerException
org.apache.jsp.view.checkInput_jsp._jspService(checkInput_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

请高手指教 哪里错了 谢谢
...全文
23 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
LingXX0103 2012-02-02
问题解决了 还是路径设置的问题
回复
LingXX0103 2012-02-02
前面发现是mdb的路径问题
把mdb放到shop文件下 然后改了代码的路径 但好像还是不正确
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2012-02-02 04:01
社区公告
暂无公告