我正面临java.sql.SQLException:没有为jdbc找到合适的驱动程序:ucanaccess:// C:/

时间:2015-04-26 08:27:35

标签: java

任何人都可以帮助我解决我在使用jdk1.8.0_45连接到ms访问时遇到的以下错误。任何帮助非常感谢。 :)

IDE:Eclipse Luna Access女士:2010

正如之前在堆栈溢出中所建议的,我在WebContent \ WEB-INF \ lib中添加了以下5个jar:

ucanaccess-2.0.9.4.jar jackcess-2.0.8.jar 的hsqldb.jar 共享记录-1.1.1.jar 公地琅-2.6.jar

控制台日志:

**Inside Servlet
inside get connection catch 
Exception : java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/ChintanDB/ChintanDB.accdb**
Apr 26, 2015 1:16:53 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [myservlettest] in context with path [/Test] threw exception
java.lang.NullPointerException
    at com.test.myservlettest.doPost(myservlettest.java:74)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    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)

Inside Servlet
Apr 26, 2015 1:17:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [myservlettest] in context with path [/Test] threw exception
java.lang.NullPointerException
    at com.test.myservlettest.doPost(myservlettest.java:74)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    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)

inside get connection catch 
Exception : java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/ChintanDB/ChintanDB.accdb

Chintandatabse.java:

package com.database;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.test.beans.*;

public class Chintandatabase 
{

    public Connection getConnection() throws SQLException 
    {
        Connection con = null;
        try 
        {
            con = DriverManager.getConnection("jdbc:ucanaccess://C:/ChintanDB/ChintanDB.accdb");
        } 
        catch (Exception e) 
        {
            System.out.println("inside get connection catch ");
            System.out.println("Exception : " + e);
        }
        return con;
    }

}

myservlettest.java(Servlet类):

public class myservlettest extends HttpServlet 
{
    private static final long serialVersionUID = 1L;
    public myservlettest()
    {
            super();

    }
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException
    {
        System.out.println("Inside Servlet");
        Chintandatabase cd = new Chintandatabase();
        Connection con = null;
        String userid ="";
        String password = "";
        try 
        {
            con = cd.getConnection();
            Statement s = con.createStatement();
                    s.executeQuery("select SOE_ID,PASSWORD from User");
                    ResultSet rs = s.getResultSet();
                    while ((rs != null) && (rs.next())) 
            {
                        userid  = rs.getString("SOE_ID");
                        password =  rs.getString("PASSWORD");
            }
                s.close();
                    con.close();
        } 
        catch (SQLException e) 
        {
            System.out.println("inside do post catch ");
            e.printStackTrace();
        }
        System.out.println("we are in service method of servlet");
        String un =req.getParameter("username") ;
        String pw =req.getParameter("userpass") ;
        String msg ="";
        if ((un.equals(userid) && pw.equals(password)))
        {   
            msg="Hello " + un + "! your login is successfull...";
        }
        else
        {
            msg="Hello " + un + "! your login is not successfull...";   
        }
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        out.println("<font size='6' color=red>" + msg + "</font>");
    }
}

1 个答案:

答案 0 :(得分:3)

您没有注册驱动程序。

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

查看官方Getting Started指南