【发布时间】:2013-07-30 12:55:58
【问题描述】:
我正在编写一个需要加载本地 SQLite 数据库的 java 程序。在我打包并在另一台计算机上尝试之前,一切都按预期工作。数据库查询似乎是唯一的问题。尝试返回 “找不到适合 jdbc:sqlite:C:\Data\Test.db 的驱动程序”。该错误让我认为它正在访问 SQL 类,但没有正确加载驱动程序本身。
- Windows 7
- 在 IntelliJ 12 中编码
- Zentus' SQLite JDBC 3.7.2
- Java SE 7 更新 25
String db_string = "C:\Data\Test.db";
try{
connection = DriverManager.getConnection("jdbc:sqlite:" + db_string);
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // 30 seconds
ResultSet rs = statement.executeQuery("select * from " + table);
while(rs.next()){
// Read the results
fileList.add(rs.getLong("modifieddate"));
}
} catch (SQLException e){
System.err.println(e.getMessage());
}
// Close the connection
finally {
try{
if(connection != null)
connection.close();
} catch (SQLException e){
System.err.println(e);
}
}
在 IntelliJ 中,我通过创建新工件并指定主类来构建 Jar。我用来读取/写入数据库信息的 SQLite 包由 IntelliJ 提取到 Jar 中。当我打开 Jar 时,我可以看到我的代码和 SQLite 代码以及它的 JDBC 驱动程序。
Manifest-Version: 1.0
Main-Class: com.myproject
我尝试过的其他计算机正在运行 Windows 8 和 Windows 7。它们都给出了相同的错误。
可能出了什么问题?
【问题讨论】: