gpt4 book ai didi

java - xerial sqlite-jdbc 3.7.2 在 OSX Mountain Lion 上返回 [SQLITE_NOTADB]

转载 作者:行者123 更新时间:2023-12-02 12:40:09 25 4
gpt4 key购买 nike

我从 iPhone 的 iTunes 备份中提取了 iOS 6 短信数据库。这是一个 sqlite3 数据库。

当我在终端中查询它时,它工作正常:

$ sqlite3 sms.db
sqlite> select * from message;

但是当我尝试使用 xerial sqlite-jdbc 查询它时我得到一个 [SQLITE_NOTADB]。

这是我使用的代码:

public class Sample {
public static void main(String[] args) throws ClassNotFoundException {
String dbFilePath = args[0];
File dbFile = new File(dbFilePath);
if (!dbFile.exists()) {
throw new IllegalArgumentException(String.format("%s does not exist", dbFilePath));
}

// load the sqlite-JDBC driver using the current class loader
Class.forName("org.sqlite.JDBC");

Connection connection = null;
try {
// create a database connection
connection = DriverManager.getConnection(String.format("jdbc:sqlite:%s", dbFilePath));
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.

ResultSet rs = statement.executeQuery("select * from message");
while (rs.next()) {
// read the result set
System.out.println(rs.getString("text"));
}
} catch (SQLException e) {
// if the error message is "out of memory",
// it probably means no database file is found
System.err.println(e.getMessage());
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
// connection close failed.
System.err.println(e);
}
}
}
}

我在 OSX Mountain Lion 上使用 xerial sqlite-jdbc 3.7.2。

最佳答案

Maven 中央存储库中最新发现的 xerial sqlite-jdbc 版本 3.7.2 似乎与 OSX Mountain Lion 不兼容。我必须使用我发现的版本 3.7.15-SNAPSHOT here .

如果您使用的是maven,则可以使用以下sh文件:

#!/bin/sh
wget https://bitbucket.org/xerial/sqlite-jdbc/downloads/sqlite-jdbc-3.7.15-SNAPSHOT.jar
mvn install:install-file -Dfile=sqlite-jdbc-3.7.15-SNAPSHOT.jar -DgroupId=org.xerial -DartifactId=sqlite-jdbc -Dversion=3.7.15-SNAPSHOT -Dpackaging=jar
rm -f sqlite-jdbc-3.7.15-SNAPSHOT.jar

我还在 Ubuntu 12.04 LTS 上尝试了 xerial sqlite-jdbc 3.7.2,并且运行良好。

关于java - xerial sqlite-jdbc 3.7.2 在 OSX Mountain Lion 上返回 [SQLITE_NOTADB],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15310667/

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