No suitable driver found (SQLite)

Fenrir86 picture Fenrir86 · May 24, 2013 · Viewed 53.9k times · Source

I hope someone can help me. I'm working on a simple application which connects with an SQLite database. Following is my connection code:

try {           
  Connection con = DriverManager.getConnection("jdbc:sqlite:myDB.sqlite");
  PreparedStatement pstm = con.prepareStatement("insert into hell(username,pssword) " +
"values ('"+tfUname.getText()+"','"+tfUpass.getText()+"')");

  pstm.close();
  con.close();
  JOptionPane.showMessageDialog(null,"Congrats, you have been registered succesfully");
  RegisterWindow rw = new RegisterWindow();
  rw.setVisible(false);
  pack();
  dispose();
} catch(SQLException ex) {
  setTitle(ex.toString());
}

This is just a window to load a user name and password in the database. The problem I have is that when I click on the button the following exception appears:

"java.sql.SQLException: No suitable driver found for jdbc:sqlite:C\\LoginJava2\\myDB.sqlite" 

(I found an example about how to connect to an SQLite database in Java, the example I found works well)

This program I'm doing it in window builder (eclipse). I'm using the same driver I use in the example I found. I don't know if I have to use another driver. In fact, I've tried with different drivers but that message still appears.

Answer

JamesB picture JamesB · May 24, 2013

Your classpath is missing the jar(s) that contain the sqlite classes and driver. You need something like sqlite-jdbc-3.7.2.jar or your applicable version.

If you are sure the jar is there, try adding this line of code before you create a connection:

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