简体   繁体   中英

Trying to connect to a SQLite database, keep getting no Suitable Driver Found

When I call The staement

c = DriverManager.getConnection("jdbc:sqlite:sample.db");   

I get a exception saying

no Suitable Driver Found for jdbc:sqlite:sample.db

The project is running in eclipse on a windows platform.

This is what I did:

  1. WENT TO properties-> java build path -> Add external jar
  2. added the file sqllite-3-16-1.jar

The code

  try {
      // exception goes off here
      c = DriverManager.getConnection("jdbc:sqlite:sample.db");     
  } catch(Exception e){
            ted=ted+1;      
  } // 

You need to load the driver class before trying to acquire the connection. Can you try the following:

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

This will throw NoClassDefFoundError if the driver jar is not on the classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM