我在JAVA应用程序中使用SQLite数据库,我在运行时创建数据库,然后创建表并执行不同的DB操作,因为SQLite必须在某个地方创建其临时文件,临时目录是设计用于保存此类文件的目录,目前在我的windows操作系统环境中,SQLite正在TEMP文件夹中创建文件,我需要更改文件夹在任何其他位置,而不是C驱动器。我尝试了以下操作
- 更改
TEMP
和TMP
的环境变量值,我如何更改sqlite创建etilqs文件的临时文件夹? - 新增问题中环境变量
SQLITE_TMPDIR
和TMPDIR
设置sqlite临时存储目录 - 我尝试
PRAGMA
语句根据以下SQLite文档https://www.sqlite.org/tempfiles.html
PRAGMA temp_store_directory = 'D:SQLite-TMP';
I have also tried with following piece of code but it didn't worked for me
Connection obj_connection = null;
Statement obj_statement = null;
try {
m_objLogManager.logInfo("Creating table 'QUEUE' if not exist ...");
obj_connection = getConnection();
m_objLogManager.logInfo("Execute PRAGMA");
try(Statement statement = obj_connection.createStatement()) {
m_objLogManager.logInfo("going to Execute PRAGMA");
statement.execute("PRAGMA temp_store_directory = 'D:\SQLite-TMP';");
m_objLogManager.logInfo("Execute PRAGMA successfully");
}
try(Statement statement = obj_connection.createStatement()) {
m_objLogManager.logInfo("getting PRAGMA");
try(ResultSet rs = statement.executeQuery("PRAGMA temp_store_directory;")) {
m_objLogManager.logInfo("getting PRAGMA successfull");
m_objLogManager.logInfo(rs.getString(1));
}
}
obj_statement = obj_connection.createStatement();
String str_sql = "CREATE TABLE IF NOT EXISTS QUEUE " +
"(Id VARCHAR(200) PRIMARY KEY NOT NULL," +
" Origin TEXT, " +
" Port INT, " +
" RegisterAt TEXT, " +
" UserName TEXT)";
obj_statement.executeUpdate(str_sql);
m_objLogManager.logInfo("Table 'QUEUE' is created if not exist");
} catch (Exception ex) {
throw ex;
} finally {
if (obj_statement != null) {
obj_statement.close();
}
if (obj_connection != null) {
obj_connection.close();
}
}
我也打开我的数据库文件在SQLite浏览器和执行以下查询PRAGMA temp_store_directory = 'D:SQLite-TMP';
但仍然SQLite在TEMP文件夹中创建临时文件,我想将临时文件的位置更改为D:SQLite-TMP
此文件夹。有人可以帮助我,因为我被困在这个问题上,请让我知道如何设置全局变量sqlite3_temp_directory
,因为我不明白如何从官方文档中设置它,谢谢。
- Sqlite数据库
- JAVA 11
首先,pragmatemp_store_directory
已弃用(参见此),因此可能不再工作。
第二,SQLITE_TMPDIR
和TMPDIR
用于类unix操作系统,看起来你在Windows上。
所以我会试着设置全局变量sqlite3_temp_directory
,就像下面提到的那样。
希望对你有帮助。