我想在我的Java Servlet Server中使用SQLite。所以我写了一个单例数据库控制器,我在我的servlet中的init
函数中初始化。当我到达以下行
Connection connection = DriverManager.getConnection(url);
我得到了这个例外:
java.sql.SQLException: No suitable driver found for jdbc:sqlite:database.db
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Controller.Database.SQLiteDataBase.getInstance(SQLiteDataBase.java:22)
at Controller.Servlets.login.loginController.init(loginController.java:45)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1174)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1090)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:770)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
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应用程序之外的新项目中获得连接,一切正常。
我正在使用Eclipse Jee Oxygen并使用Add External JARs ..来添加sqlite-jdbc-3.21.0.jar
我该怎么做才能解决这个问题?我已经尝试过.db文件的绝对路径和相对路径。
答案 0 :(得分:1)
您需要将sqlite-jdbc-3.21.0.jar添加到您的服务器类路径中,您可以将它放在tomcat服务器的lib文件夹中,或者您可以将此jar放在WEB-INF / lib文件夹中你的项目。