gpt4 book ai didi

Java SQLException 与 JDBC - SQLITE_MISUSE

转载 作者:太空宇宙 更新时间:2023-11-04 12:49:19 28 4
gpt4 key购买 nike

我在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com