在Mac OSX Mavericks上使用Xerial的JDBC SQLite的SQLITE_NOTADB错误(10.9.1)

时间:2014-02-17 19:17:03

标签: java macos sqlite jdbc

从JDBC读取SQLite数据库时遇到以下错误:[SQLITE_NOTADB] File opened that is not a database file (file is encrypted or is not a database)。到目前为止,我可以告诉这个数据库没有加密(见下面的标题),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

数据库标题

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  |................|
*

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我今天遇到了同样的问题,原因是我用旧的打开了新的SQLite数据库(sqlite-jdbc版本:3.21.0.1) “ SQLite管理员(版本:0.8.3.2公开测试版),年份:2013”​​。 所有SQL语句都没有任何问题,但保存后,无法再连接到数据库(通过JDBC)。

因此我将DB Programm更改为“ SQL浏览器for SQLite 3.9.1 ,2017年”,所有内容再次运行!

这需要花费时间和精力,因为我没有考虑过......但也许我可以帮助别人用我的解决方案节省一些时间: - )

相关问题