user3286170
user3286170

Reputation: 11

ClassNotFoundException: org.sqlite.JDBC

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

Answers (4)

Mysterious Cat
Mysterious Cat

Reputation: 1

I followed these steps for adding the path to a .jar file in intelliJ:

  1. Go to File->Prject Structure->SDKs
  2. Select Classpath tab
  3. Select Your SDK (probably first in a list)
  4. Click "+" icon and add your .jar

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

Calvin Taylor
Calvin Taylor

Reputation: 694

in my case I was using gradle and needed to add

dependencies {
    implementation 'org.sqlite:sqlite-jdbc:3.25.2'
}

Upvotes: 0

Javu Man
Javu Man

Reputation: 11

You can directly add sqlite-jdbcXXX.jar to your tomcat/lib.

Upvotes: 1

safaiyeh
safaiyeh

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

Related Questions