【发布时间】:2023-01-24 16:39:31
【问题描述】:
我正在尝试在使用 maven 和 java8 的 java 应用程序中使用 sqlite。
通过我的应用程序,我能够创建数据库和表。
但是当我尝试执行选择查询时,它会在 PreaparedStatement 上抛出异常。
笔记:
我的数据库在D:\Clients\Client1\sqlite\clientdb.db
public boolean testSelectQuery(String val1, String val2) {
String sql = "SELECT *FROM test_table WHERE col1 = ? and col2 = ? ";
Connection connection = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
connection = DriverManager.getConnection("jdbc:sqlite:D:\Clients\Client1\sqlite\clientdb.db");
pstmt = connection.prepareStatement(sql);**// Throwing exception**
// set the value
pstmt.setString(1, val1);
pstmt.setString(2, val2);
rs = pstmt.executeQuery(sql);
return rs.isBeforeFirst();
} catch (SQLException e) {
return false;
} finally {
//close resources
}
}
尝试在表之前添加数据库名称数据库.表名但它也不起作用,我看到了多个问题,但我的问题没有得到解决
【问题讨论】:
-
"jdbc:sqlite:D:\Clients\Client1\sqlite\clientdb.db"你应该转义那些反斜杠:"jdbc:sqlite:D:\\Clients\\Client1\\sqlite\\clientdb.db"