2
從JDBC讀取SQLite數據庫時出現以下錯誤:[SQLITE_NOTADB] File opened that is not a database file (file is encrypted or is not a database)
。據我可以告訴這個數據庫沒有加密(見下面的標題),並且sqlite3能夠執行相同的命令而沒有任何錯誤或警告。在Mac OSX Mavericks上使用Xerial的JDBC SQLite時出現SQLITE_NOTADB錯誤(10.9.1)
任何建議/想法解決這個問題?
的源代碼
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
DB頭
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 |[email protected] .......||
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 |................|
*