Reputation: 11
I'm trying to set up a simple database for an Android app using sqlite but got the following error:
java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at testDB.main(testDB.java:16)
Here is my code:
public class testDB {
public static void main(String args[]) {
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:/Users/Dropbox/csProject/test.db", "", "");
}
}
I have added sqlite-jdbc4-3.8.2-SNAPSHOT.jar in the library and I also tried to create a path in my home directory but am still getting the same error..
Upvotes: 1
Views: 12977
Reputation: 1
I followed these steps for adding the path to a .jar file in intelliJ:
And this was no longer need to add some code like, all works properly
try{
Class.forName("org.sqlite.JDBC");
} catch (Exception e){
...
}
I think the problem was caused by problems in jar registration, not by lazy package load
Upvotes: -1
Reputation: 694
in my case I was using gradle and needed to add
dependencies {
implementation 'org.sqlite:sqlite-jdbc:3.25.2'
}
Upvotes: 0
Reputation: 1715
You have to add the .jar to your project. You can simply do that by opening Eclipse, right click the .jar files, then add to project.
Upvotes: 1