Jakub Gadawski
Jakub Gadawski

Reputation: 354

Java - SQLite connection (No suitable driver found for JDBC:sqlite:main.db)

I have problem with SQLite connection on my Java project. Error looks like this :

No suitable driver found for JDBC:sqlite:main.db

That's my code:

public static void main(String[] args)  {

    Connection c = null;
    try {
      //  Class.forName("org.sqlite.JDBC");
        String url = "JDBC:sqlite:main.db";
        c = DriverManager.getConnection(url);
        System.out.println("Connection to sql");
    } catch ( SQLException e ) {
        System.err.println( e.getMessage() );
    } finally {
        try{
            if( c!= null ) {
                c.close();
            }
        }catch( SQLException ex )
        {
            System.out.println(ex.getMessage());
        }
    }
}

Can You help me please?

Upvotes: 3

Views: 16471

Answers (3)

Babatunde Adeyemi
Babatunde Adeyemi

Reputation: 14438

If you're using maven, ensure that the scope isn't specified as test.i.e.

<dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.18.0</version>
</dependency>

Upvotes: 6

duffymo
duffymo

Reputation: 308733

"No suitable driver" means that the connection URL is incorrect for the JDBC driver JAR that was loaded.

Case matters: it should be jdbc:sqlite:main.db. Please read the tutorial.

Upvotes: 3

Anant666
Anant666

Reputation: 416

I think you have not added the SQLITE JDBC driver to your classpath. Just download the jar FROM HERE and add it to your classpath. Your error would be resolved.

You should also have a look on This answer and This resource. By reading both of them you will learn more about SQLITE as well as how to make a connection with JDBC.

Upvotes: 0

Related Questions