org.sqlite.JDBC will not be found
Hello,
I'm just trying to generate a connection to a SQLITE database. Here you will see the code:
private void getConnection() throws ClassNotFoundException, SQLException {
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:SQLiteTest1.db");
initialise();
}
When I run the application in InteliJ IDEA 2016.2.2 I will get always the ClassNotFoundException
java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.linuxmaker.SQLiteTest.getConnection(SQLiteTest.java:30)
at com.linuxmaker.SQLiteTest.displayUsers(SQLiteTest.java:21)
at com.linuxmaker.App.main(App.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
I understand org.sqlite.JDBC will not be found, because it seems not to appear in the classpath of the project.
But I have insert sqlite-jdbc-3.8.11.2.jar over CTRL+ALT+SHIFT+S "Libraries":
.idea/libraries/sqlite_jdbc_3_8_11_2.xml:
<component name="libraryTable">
<library name="sqlite-jdbc-3.8.11.2">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/sqlite-jdbc-3.8.11.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/sqlite-jdbc-3.8.11.2.jar!/" />
</SOURCES>
</library>
</component>
In the left pane of the Editor where the tree of packages in my project are shown, I can see under "Libraries" the directory "org". In "org" I found "sqlite" and the Class JDBC. It is also installed.
But why "org.sqlite.JDBC" will not be found?
Can someone help me?
Thanks
Andreas
请先登录再写评论。
It looks like you have added the library to the project, but didn't add this library to the dependencies of the module: http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html.
Hello Serge,
I don't understand it. When I open the module "Modules" then I see on the right pane also sqlite-jdbc-3.8.11.2 included with the scope "compile". Or should I add the sqlite-jdbc-3.8.11.2.jar file additonally on that pane?
Looks good, but I can't reproduce it with the same setup:
Maybe your .jar is invalid or is missing files (like it contains only sources, but no .class files).
Please try this sample project that I've prepared: ftp://ftp.intellij.net/pub/.idea/SQLiteDemo.zip.
Thanks Serge,
for your file of demonstration. Unfortunally it crashs still again.
Here are my settings for module Uebungsprojekt:

And there are the settings for the included libraries:
There is some setting which could be wrong. But I don't know which and where.
Best regards
Andreas
Okay, I don't know why, but now it runs.
Thanks for your support!
Bye