Issue
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 insert a user name and password into the database. When I click the button following exception appears:
"java.sql.SQLException: No suitable driver found for jdbc:sqlite:C\\LoginJava2\\myDB.sqlite"
I found an example of how to connect to an SQLite database in Java which works well. I'm doing this in WindowBuilder (Eclipse), using the same driver from the example. I've tried different drivers but that message still appears.
Solution
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");
Answered By - JamesB
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.