Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

sqlite

jdbc

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?

like image 532
Jakub Gadawski Avatar asked Apr 29 '26 09:04

Jakub Gadawski


2 Answers

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>
like image 152
Babatunde Adeyemi Avatar answered May 01 '26 23:05

Babatunde Adeyemi


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

like image 30
duffymo Avatar answered May 01 '26 23:05

duffymo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!