问题描述
我希望有人可以帮助我。我正在研究一个与SQLite数据库连接的简单应用程序。以下是我的连接代码: 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,你已经成功注册);
RegisterWindow rw = new RegisterWindow();
rw.setVisible(false);
pack();
dispose();
} catch(SQLException ex){
setTitle(ex.toString());
}
这只是在数据库中加载用户名和密码的窗口。我遇到的问题是,当我点击按钮时,会出现以下异常:
java.sql.SQLException:找到jdbc的驱动程序:sqlite:C \\\LoginJava2\\\myDB.sqlite
(我发现了一个关于如何连接到Java的SQLite数据库的例子,我发现这个例子很好)
这个程序我在窗口构建器(eclipse )。我正在使用与我发现的示例中使用的相同的驱动程序。我不知道我是否必须使用另一个驱动程序。事实上,我已经尝试过不同的驱动程序,但仍然显示该消息。
您的类路径缺少jar包含sqlite类和驱动程序。您需要像sqlite-jdbc-3.7.2.jar或您适用的版本。
如果您确定该jar存在,请尝试在创建连接之前添加以下代码行:
的Class.forName( org.sqlite.JDBC);
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.
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");
这篇关于找不到合适的驱动程序(SQLite)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!