3

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?

3 Answers 3

6

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>
Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

0

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.

4 Comments

Please include the relevant parts in your answer, don't only rely on links only. On top of that, it doesn't even address the actual problem: the wrong case of "JDBC:..." instead of "jdbc:...".
@Mark honestly I didn't knew the actual answer. Hence I gave the working examples links so that the questioner will benefit from some extra details given on those links, and that might give an extra edge to his knowledge and expertise. Thanks for pointing out, I will take care from the next time.
In that case it is better to leave a comment, instead of answering.
yeah sure, I was not fully aware of these stackoverflow rules. Thanks,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.