问题描述
我正在尝试将sqlite-File读入内存以获得更好的性能,在关闭我的应用程序时我想将其写回到hdd。
I'm trying to read a sqlite-File into memory for better performance, when closing my application I want to write it back to hdd.
我是在Java中使用 jdbc (3.7.2)驱动程序。
I'm using the jdbc (3.7.2) driver in Java.
根据文档,我的代码看起来像
According to the docs, my Code looks like
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
已打开,但如果我想在其上执行语句,则表示内部没有表或数据。它似乎没有恢复任何东西。
The file exists (and its a valid sqlite db), this._conn
is open, but if I want to execute statements on it, it appears that there is no table nor data inside. It seems it doesn't restore anything.
有关如何进一步解决/调试的任何建议吗?
Any suggestions on how to solve/debug that further?
(顺便说一下 - 如果我在我的连接上使用 stat.executeUpdate(backup to test.db)
,它会备份我的空:memory:db ...)
(by the way - if I use stat.executeUpdate("backup to test.db")
on my connection, it backups my empty :memory: db...)
推荐答案
引号和 stat.close()
无关紧要,根据链接:`',我测试过。但是当文件路径包含空格时引用帮助。
The quotes and stat.close()
don't matter, according to the link: `https://bitbucket.org/xerial/sqlite-jdbc/wiki/Usage', which I have tested. Quotes help when file path contains spaces, though.
我认为这可能是由于jdbc驱动程序。尝试使用Xerial的SQLite JDBC驱动程序,这对我来说很好。
I think it maybe due to the jdbc driver. Try Xerial's JDBC driver for SQLite, which works fine for me.
这篇关于使用Java从磁盘备份和恢复sqlite到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!