我想通過訪問數據庫在我的頁面上創建登錄表單。這裏是連接代碼如何將微軟訪問數據庫連接到jsp tomcat?
<%@ 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專業版64位,和Tomcat 7.0,JRE 6 64
優秀的開端。現在,安裝了Access數據庫引擎的64位版本? –
@GordThompson如何檢查? – greenthunder
'Windows控制面板'>'管理工具'>'數據源(ODBC)'。在「驅動程序」選項卡上,是否列出了「Microsoft Access Driver(* .mdb,* .accdb)」? –