我想通过访问数据库在我的页面上创建一个登录表单。这是连接代码
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + application.getRealPath("WEB-INF/travDB.accdb"));
Statement st = con.createStatement(1004,1008);
%>
当我尝试登录时,出现错误
type Exception report
message An exception occurred processing JSP page /Advance/Course1/connect.jsp at line 4
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /Advance/Course1/connect.jsp at line 4
1: <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
2: <%
3: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
4: Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + application.getRealPath("WEB-INF/travDB.accdb"));
5: Statement st = con.createStatement(1004,1008);
6: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Advance.JSP.Project.JSP_005fH2Soal2.JSP_005fH2Soal2_005fT213.doLogin_jsp._jspService(doLogin_jsp.java:119)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.Advance.JSP.Project.JSP_005fH2Soal2.JSP_005fH2Soal2_005fT213.doLogin_jsp._jspService(doLogin_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
我已在文件夹Course1中创建了WEB-INF文件夹,而connect.jsp也在文件夹Course1中。 我该怎么办?
我正在使用Windows 7 Professional 64位和tomcat 7.0版,jre 6 64位
答案 0 :(得分:2)
您使用的是 32位MS Access数据库吗? 您提到您有 64位操作系统和JRE也是64位,但如果您有32位Access数据库,则会出现上述异常。 See this similar post。
您无法从64位程序直接连接到32位Access ODBC驱动程序。
虽然Microsoft使用Windows(32位和64位)分发32位ODBC Microsoft Access驱动程序,但它不会使用Windows 64分发64位MsAccess驱动程序。可以从Microsoft获得64 bit Access ODBC Driver。下载和安装64位MS Access驱动程序时存在一些问题
Refer this answer
类似帖子