gpt4 book ai didi

java - Mac OSX Mavericks (10.9.1) 上 Xerial 的 JDBC SQLite 出现 SQLITE_NOTADB 错误

转载 作者:行者123 更新时间:2023-11-30 11:22:11 30 4
gpt4 key购买 nike

从 JDBC 读取 SQLite 数据库时出现以下错误:[SQLITE_NOTADB] 打开的文件不是数据库文件(文件已加密或不是数据库)。据我所知,这个数据库没有加密(见下面的标题)并且 sqlite3 能够执行相同的命令而没有任何错误或警告。

有什么解决这个问题的建议/想法吗?

源代码

package foo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection connection = null;
Statement statement = null;
String fn = "/Users/jerome/db.sql";
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + fn);
statement = connection.createStatement();
statement.executeQuery("SELECT 1 FROM sqlite_master");
}
}

如何运行

java -cp /Users/jerome/.m2/repository/org/xerial/sqlite-jdbc/3.7.2/sqlite-jdbc-3.7.2.jar:foo.jar foo.Test

堆栈跟踪

Exception in thread "main" java.sql.SQLException: [SQLITE_NOTADB]  File opened that is not a database file (file is encrypted or is not a database)
at org.sqlite.DB.newSQLException(DB.java:383)
at org.sqlite.DB.newSQLException(DB.java:387)
at org.sqlite.DB.throwex(DB.java:374)
at org.sqlite.NestedDB.prepare(NestedDB.java:134)
at org.sqlite.DB.prepare(DB.java:123)
at org.sqlite.Stmt.executeQuery(Stmt.java:121)
at foo.Test.main(Test.java:16)

使用 sqlite3

sqlite3 ~/Desktop/db.sql "SELECT 1 FROM sqlite_master"
1
1
[...]
1

数据库 header

hexdump -C ~/Desktop/db.sql | head
00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 |SQLite format 3.|
00000010 10 00 02 02 00 40 20 20 00 00 2e 0b 00 00 01 7c |.....@ .......||
00000020 00 00 00 00 00 00 00 00 00 00 00 21 00 00 00 04 |...........!....|
00000030 00 00 00 00 00 00 00 24 00 00 00 01 00 00 00 00 |.......$........|
00000040 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2e 0b |................|
00000060 00 2d e2 25 05 00 00 00 01 0f fb 00 00 00 00 25 |.-.%...........%|
00000070 0f fb 04 bf 04 20 03 78 02 cd 02 22 01 92 00 f9 |..... .x..."....|
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*

最佳答案

3.7.2 似乎存在兼容性问题。当我切换到 3.7.15-M1 时,问题消失了。我不确定为什么。

关于java - Mac OSX Mavericks (10.9.1) 上 Xerial 的 JDBC SQLite 出现 SQLITE_NOTADB 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21837462/

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