Backup and restore sqlite from disk to memory in Java

后端 未结 2 1255
孤独总比滥情好
孤独总比滥情好 2020-12-31 15:18

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.

I\'m using the jdbc (3.7.2

2条回答
  •  一个人的身影
    2020-12-31 15:41

    It looks like you are missing two things: 1) The quotes around the file name, and 2) stat.close. Try the following:

    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();
    }
    

    That was the only way I could get it to work with Xerial SQLite JDBC version 3.7.15-M1. I do not think that the version matters much in this case.

提交回复
热议问题