Guy Hagemans
Guy Hagemans

Reputation: 510

java.sql.SQLException: No suitable driver found for jdbc:sqlite

My Java program (one of my very first) seems to be hanging at the following line of standard code:

    Class.forName("org.sqlite.JDBC");

    Connection c = null;
    Statement stmt = null;
    c = DriverManager.getConnection("jdbc:sqlite:test.db");
    c.setAutoCommit(false);

I'm recieving the following error:

java.sql.SQLException: No suitable driver found for jdbc:sqlite:test.db

However, when running the java application I'm providing the correct location of the jdbc driver (I think);

sudo java -cp ./jsoup-1.7.3.jar:./sqlite-jdbc-3.7.2.jar:. <AppName>

any idea how to proceed?
thanks a million

Upvotes: 2

Views: 4817

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

sudo java -cp ./jsoup-1.7.3.jar:./sqlite-jdbc-3.7.2.jar:.

any idea how to proceed? thanks a million

Yes. Two major problems I see. One, unless you have a very good reason, don't run your program with sudo. It could cause you major pain later if you do.

Second, your classpath doesn't look correct. jar files are located on it. The first part should be the path to search and the second the jars to search for.

java -cp ".:jsoup-1.7.3.jar:sqlite-jdbc-3.7.2.jar" ...

Finally, I assume you downloaded from sqlite here and jsoup here and have the jar files in your current directory and if it still isn't working you should check those files are correct.

$ sha1sum sqlite-jdbc-3.7.2.jar 
cea9f7f8e6bcb580d953a8651fb8391640de0f85  sqlite-jdbc-3.7.2.jar
$ sha1sum jsoup-1.7.3.jar 
ab1f22cadc2f8b514e55ba368f5128056fe304da  jsoup-1.7.3.jar

Upvotes: 1

Related Questions