2013-10-20 90 views
0

我想通過訪問數據庫在我的頁面上創建登錄表單。這裏是連接代碼如何將微軟訪問數據庫連接到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

+0

優秀的開端。現在,安裝了Access數據庫引擎的64位版本? –

+0

@GordThompson如何檢查? – greenthunder

+0

'Windows控制面板'>'管理工具'>'數據源(ODBC)'。在「驅動程序」選項卡上,是否列出了「Microsoft Access Driver(* .mdb,* .accdb)」? –

回答

2

是否使用32位MS Access數據庫
你提到你有64位OS和JRE也是64位,但是如果你有32位的Access數據庫,那麼上面提到的異常會發生。 See this similar post

不能從64位程序直接連接到32位Access ODBC驅動程序。
雖然Microsoft在Windows上分發32位ODBC Microsoft Access驅動程序(32位爲32位3232329,),但它不會在Windows 64上分發64位MsAccess驅動程序。有一個可從Microsoft獲得的64 bit Access ODBC Driver。下載和安裝64位MS Access驅動程序有一些問題。
Refer this answer

類似的帖子

+0

上列出,在* .accdb的Microsoft訪問中已經有* .mdb。我應該再添加一次嗎? – greenthunder