ucanaccess 与 java servlet 程序

Posted

技术标签:

【中文标题】ucanaccess 与 java servlet 程序【英文标题】:Ucanaccess with java servlet program 【发布时间】:2014-08-13 07:20:50 【问题描述】:

您好,我正在尝试使用 ucanaccess 驱动程序连接访问数据库,但最后我收到以下错误

Aug 13, 2014 12:41:00 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;.
Aug 13, 2014 12:41:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.jee.server:Hrmanpowersystem' did not find a matching property.
Aug 13, 2014 12:41:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Aug 13, 2014 12:41:00 PM org.apache.tomcat.util.net.NioselectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 13, 2014 12:41:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Aug 13, 2014 12:41:00 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 13, 2014 12:41:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1039 ms
Aug 13, 2014 12:41:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 13, 2014 12:41:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.9
Aug 13, 2014 12:41:01 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [254] milliseconds.
Aug 13, 2014 12:41:02 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Aug 13, 2014 12:41:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Aug 13, 2014 12:41:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Aug 13, 2014 12:41:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1793 ms
java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C://Users//Satish Aiyappa//Documents//test.accdb
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.manpower.logincheck.doPost(logincheck.java:49)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

我的 servlet 代码在这里

package com.manpower;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class logincheck
 */
@WebServlet("/logincheck")
public class logincheck extends HttpServlet 
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public logincheck() 
        super();
        // TODO Auto-generated constructor stub
    

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        // TODO Auto-generated method stub
        doPost(request,response);
    

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        // TODO Auto-generated method stub
        String uname=request.getParameter("uname");
        String pass=request.getParameter("pass");
        PrintWriter out=response.getWriter();
        try
        
            Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C://Users//Satish Aiyappa//Documents//hrmanpowersystem.accdb");
            Statement s = conn.createStatement();
            ResultSet rs=s.executeQuery("select uname,password from login where uname='"+uname+"'and password='"+pass+"'");
            if(rs.next())
            

                response.sendRedirect("Navigationscreen.jsp");


            
            else
            

                response.sendRedirect("Loginscreen.jsp");

            

        
        catch(Exception e)
        

        e.printStackTrace();    
        



    


我有 java8 的 tomcat 8 服务器,所以我无法判断错误在哪里。

【问题讨论】:

UCanAccess JAR 和其他支持 JAR 是否在 Web 应用程序 lib 文件夹 (WEB_INF/lib) 中?如果在调用 DriverManager.getConnection() 之前添加行 Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); 会发生什么? 它的工作卢克谢谢 【参考方案1】:
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C://Users//Satish Aiyappa//Documents//hrmanpowersystem.accdb");

应该是

Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Satish Aiyappa/Documents/hrmanpowersystem.accdb");

仅在jdbc:ucanaccess: 和路径之间使用//,路径使用单个/

【讨论】:

以上是关于ucanaccess 与 java servlet 程序的主要内容,如果未能解决你的问题,请参考以下文章

有没有办法在 UcanAccess 中强制从磁盘读取?

java.lang.ClassNotFoundException:net.ucanaccess.jdbc.ucanaccessDriver

Java 错误 - net.ucanaccess.jdbc.UcanaccessSQLException:格式错误的字符串:'

ucanaccess 驱动程序是不是处理多个并发 Java 应用程序?

java.Sql.SQLException,无法加载类 net.ucanaccess.jdbc.UcanaccessDriver

UCanAccess Java 执行错误