【问题标题】:org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: test_table)org.sqlite.SQLiteException:[SQLITE_ERROR] SQL 错误或缺少数据库(没有这样的表:test_table)
【发布时间】: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"

标签: java sqlite


【解决方案1】:

要查看的一些步骤:

  1. 检查路径是否正确。
  2. 检查是否配置了 SQLITE 的 JDBC 驱动程序或者它是否在类路径中。
  3. 请验证 SQLite 中是否存在 test_table。 (迁移是否设置为真?)

    关于这一点的最后一条评论,避免使用 SQLite,而是使用 MySQL、PostGresql。

【讨论】:

  • “避免使用 SQLite,而是使用 MySQL、PostGresql。”为什么?基于什么假设?
猜你喜欢
  • 2021-07-31
  • 1970-01-01
  • 1970-01-01
  • 2019-03-04
  • 1970-01-01
  • 2022-06-15
  • 1970-01-01
  • 2014-06-03
  • 1970-01-01
相关资源
最近更新 更多