1

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..

2
  • 2
    sqlite-jdbc4-3.8.2-SNAPSHOT.jar is not in your classpath Commented Feb 8, 2014 at 3:39
  • stackoverflow.com/a/43234518/6756523 Commented Apr 5, 2017 at 14:46

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

in my case I was using gradle and needed to add

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

Comments

-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.