Java SQLException 与 JDBC - SQLITE_MISUSE

标签 java sql sqlite jdbc twitter4j

我在 Java 应用程序中使用 SQlite。如果我运行我的程序,它会在某个时候出错。

有时这是一个简单的异常,有时则是 JVM 发生 fatal error 。

java.sql.SQLException: [SQLITE_MISUSE] Library used incorrectly (out of memory)

<小时/>

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006d587ab0, pid=7036, tid=6364

JRE version: Java(TM) SE Runtime Environment (8.0_73-b02) (build 1.8.0_73-b02) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.73-b02 mixed mode windows-amd64 compressed oops) Problematic frame: C [sqlite-3.8.11.2-6df82281-eaf0-4204-a962-ce1e48ddd89f-sqlitejdbc.dll+0x7ab0]

Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as: C:\Users\UltraMouse\workspace\co.windall.twitter\hs_err_pid7036.log

If you would like to submit a bug report, please visit: http://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

导致此问题的代码行是

ResultSet rs = stmt.executeQuery("SELECT * FROM User WHERE id=" + id.toString() + ";");

它不一致,每次都发生在不同的点(此代码在循环中),但它总是发生。

这是我的完整源文件: http://pastebin.com/RKKVdNZ8 http://pastebin.com/fVaa93Rk

我每次都干净地运行它(我删除了数据库文件)。目前在 file1 的第 102 行失败。

我不知道该怎么办:(

是的,这些 Twitter 键现在可以使用,但仅限于读取访问,我将它们留在那里,以便您可以在需要时尝试该应用程序。

最佳答案

很难准确地看出问题出在哪里,但您绝对应该在每次操作后关闭语句和 ResultSet

这很可能导致您看到的内存泄漏:

Statement stmt = connection.createStatement();

应该在每个新操作之前调用并且

stmt.close();

应在每次操作后调用。所以总而言之,你的主循环应该如下所示:

for (Long id : ids) {
    Statement stmt;
    ResultSet rs;
    try {
        st = connection.createStatement();
        rs = stmt.executeQuery("...");

        if (rs.next()) {
            Long ft = rs.getLong("followedThem");
            rs.close();
            st.close();

            st = connection.createStatement();
            String sql = "...";

            if (ft != null && ft == -1) {
                sql = x;
            } else {
                sql = y;
            }

            st.executeUpdate(sql);
            st.close();
        } catch (SQLException e) {}
    }
}

关于Java SQLException 与 JDBC - SQLITE_MISUSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35996776/

相关文章:

sqlite - 在 Azure 存储上托管 SQLite DB?

java - 在 Azure AD 中生成用于 SSO 的 IDP 证书

java - 如何检查字符串是否包含字母表中的所有字母?

sql - Ruby on Rails中的单步批处理删除

sql - 是否有任何缺点会阻碍您向表列添加索引?

iphone - 将 map 坐标(lan,& long)存储在 sqlite 数据库中

python - 从仅包含部分列数据的sqlite中检索行

java - TypedQuery - EntityManager 中的 createQuery(String) 无法应用于 (String, java.lang.Class<models.Person>)

java - 如何确定 JSON 属性的数据类型?

mysql - 如何减少这个SQL查询的时间