使用Java从磁盘备份和恢复sqlite到内存
发布时间:2020-05-24 22:51:33 所属栏目:Java 来源:互联网
导读:我正在尝试将sqlite-File读入内存以获得更好的性能,在关闭我的应用程序时我想将其写回到hdd. 我在Java中使用jdbc(3.7.2)驱动程序. 根据文档,我的代码看起来像 this._conn = DriverManager.getConnection(jdbc:sqlite:);Statement stat = this._conn.createSta
|
我正在尝试将sqlite-File读入内存以获得更好的性能,在关闭我的应用程序时我想将其写回到hdd. 我在Java中使用jdbc(3.7.2)驱动程序. 根据文档,我的代码看起来像 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”),它会备份我的空:memory:db …) 解决方法看起来你错过了两件事:1)文件名周围的引号,以及2)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的唯一方法.在这种情况下,我不认为这个版本很重要. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
