如何更改SQLITE数据库以在其他任何文件夹中创建临时文件,而不是使用Java创建临时文件夹?
我在Java应用程序中使用SQLITE数据库,在该应用程序中我在运行时创建数据库,然后创建表并执行不同的DB操作,因为SQLite必须在某处创建其临时文件,而临时目录是旨在拥有此类文件的目录,当前在我的Windows OS环境中,SQLite正在使用temp文件夹创建文件,我需要在C驱动器以外的任何其他位置更改文件夹。 我已经尝试以下操作
- 更改
temp
和tmp
的环境变量值,如下述问题如何更改sqlite创建etilqs文件的temp文件夹? - 添加新的环境变量
sqlite_tmpdir 和
tmpdir
下面提到的问题 设置sqlite temp store directory - 我尝试了
pragma
语句遵循SQLite文档 https://www.sqlite.org/tempfiles.html
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浏览器中打开我的db文件,并在查询之后执行执行 pragma temp_store_directory ='d:\ sqlite-tmp';
但是,仍然在temp文件夹中创建临时文件的sqlite我想将临时文件的位置更改为d:\ sqlite-tmp
此文件夹。 任何人都可以帮助我,因为我陷入了这个问题,请让我知道如何设置全局变量sqlite3_temp_directory
,因为我不明白如何从官方文档谢谢。
我的环境
- Windows 10
- Sqlite数据库
- Java 11
I am using SQLite database within my JAVA application in which I create database on runtime and then create tables and perform different DB operations, as SQLite has to create its temporary files somewhere, and the temporary directory is the directory that is designed to hold such files, currently in my windows OS environment SQLite is creating files in TEMP folder, I need to change the folder in any other location other than C drive.
I have tried following operations
- Change Environment variable values of
TEMP
andTMP
in mentioned following question How can I change the temp folder where sqlite creates etilqs files? - Add new Environment variable
SQLITE_TMPDIR
andTMPDIR
mentioned in following question
Setting sqlite temp store directory - I tried
PRAGMA
statements according to following SQLite documentation
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();
}
}
I also open my DB file in SQLite browser and execute following queryPRAGMA temp_store_directory = 'D:\SQLite-TMP';
But still SQLite creating temporary files in TEMP folder I want to change the location of temporary files into D:\SQLite-TMP
this folder.
can anyone helped me as i am stuck in this problem, please let me know how to set the global variable sqlite3_temp_directory
because I don't understand how to set it up from official documentation thanks.
My Environment
- Windows 10
- Sqlite database
- JAVA 11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,pragma
temp_store_directory
已弃用(请参阅其次,
sqlite_tmpdir
和tmpdir
适用于unix like oss,看起来您在Windows上。因此,我将尝试设置全局变量
sqlite3_temp_directory
,如上所述希望这会有所帮助。
First, pragma
temp_store_directory
is deprecated (see this), so might not work anymore.Second,
SQLITE_TMPDIR
andTMPDIR
are for unix-like OSs, and looks like you're on Windows.So I would try to set the global variable
sqlite3_temp_directory
as mentioned here at the bottom.Hope this helps.