[英]How to change sqlite database to create temporary files in any other folder instead of temp folder using JAVA?
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.我在我的 JAVA 应用程序中使用 SQLite 数据库,在该应用程序中,我在运行时创建数据库,然后创建表并执行不同的 DB 操作,因为 SQLite 必须创建其临时文件的目录,目前在我的 windows 操作系统环境 SQLite 正在 TEMP 文件夹中创建文件,我需要更改 C 驱动器以外的任何其他位置的文件夹。 I have tried following operations
我尝试过以下操作
TEMP
and TMP
in mentioned following question How can I change the temp folder where sqlite creates etilqs files?TEMP
和TMP
的环境变量值如何更改 sqlite 创建 etilqs 文件的临时文件夹?SQLITE_TMPDIR
and TMPDIR
mentioned in following question Setting sqlite temp store directorySQLITE_TMPDIR
和TMPDIR
PRAGMA
statements according to following SQLite documentation https://www.sqlite.org/tempfiles.htmlPRAGMA
语句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 query PRAGMA temp_store_directory = 'D:\SQLite-TMP';
我还在 SQLite 浏览器中打开我的数据库文件并执行以下查询
PRAGMA 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.但仍然 SQLite 在 TEMP 文件夹中创建临时文件 我想将临时文件的位置更改为
D:\SQLite-TMP
这个文件夹。 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.任何人都可以帮助我,因为我陷入了这个问题,请让我知道如何设置全局变量
sqlite3_temp_directory
因为我不明白如何从官方文档中设置它谢谢。
My Environment我的环境
First, pragma temp_store_directory
is deprecated (see this ), so might not work anymore.首先,pragma
temp_store_directory
已被弃用(请参阅this ),因此可能不再有效。
Second, SQLITE_TMPDIR
and TMPDIR
are for unix-like OSs, and looks like you're on Windows.其次,
SQLITE_TMPDIR
和TMPDIR
用于类似 unix 的操作系统,看起来您使用的是 Windows。
So I would try to set the global variable sqlite3_temp_directory
as mentioned here at the bottom.所以我会尝试设置全局变量
sqlite3_temp_directory
,如底部所述。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.