我从 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。