使用Java从磁盘备份和恢复sqlite到内存

我正在尝试将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的唯一方法.在这种情况下,我不认为这个版本很重要.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...