我正在尝试将 sqlite 文件读入内存以获得更好的性能,当关闭我的应用程序时,我想将其写回硬盘。
我正在使用jdbc(3.7.2) Java 驱动程序。
根据文档,我的代码看起来像
this._conn = DriverManager.getConnection("jdbc:sqlite:");
Statement stat = this._conn.createStatement();
File dbFile = new File(this._config.GetDataBaseFile());
if (dbFile.exists()) {
this._logger.AddInfo("File exists.");
stat.executeUpdate("restore from " + dbFile.getAbsolutePath());
}
该文件存在(并且它是一个有效的 sqlite 数据库),this._conn
是打开的,但是如果我想在上面执行语句,看起来里面没有表,也没有数据。似乎并不能恢复任何东西。
关于如何进一步解决/调试这个问题有什么建议吗?
(顺便说一句 - 如果我使用stat.executeUpdate("backup to test.db")
在我的连接上,它备份我的空:内存:数据库...)
看起来你错过了两件事:
- 文件名周围的引号。
-
stat.close
.
请尝试以下操作:
this._conn = DriverManager.getConnection("jdbc:sqlite:");
Statement stat = this._conn.createStatement();
File dbFile = new File(this._config.GetDataBaseFile());
if (dbFile.exists()) {
this._logger.AddInfo("File exists.");
stat.executeUpdate("restore from '" + dbFile.getAbsolutePath() + "'");
stat.close();
}
这是我可以让它与 Xerial SQLite JDBC 版本 3.7.15-M1 一起使用的唯一方法。我认为在这种情况下版本并不重要。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)