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?
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>
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With