简体   繁体   English

如何更改 sqlite 数据库以使用 JAVA 在任何其他文件夹而不是临时文件夹中创建临时文件?

[英]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我尝试过以下操作

  1. Change Environment variable values of TEMP and TMP in mentioned following question How can I change the temp folder where sqlite creates etilqs files?在以下问题中更改TEMPTMP的环境变量值如何更改 sqlite 创建 etilqs 文件的临时文件夹?
  2. Add new Environment variable SQLITE_TMPDIR and TMPDIR mentioned in following question Setting sqlite temp store directory添加以下问题设置 sqlite 临时存储目录中提到的新环境变量SQLITE_TMPDIRTMPDIR
  3. I tried PRAGMA statements according to following SQLite documentation https://www.sqlite.org/tempfiles.html我根据以下 SQLite 文档https://www.sqlite.org/tempfiles.C9265FDCZ8A2FC2尝试了PRAGMA语句

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我的环境

  • Windows 10 Windows 10
  • Sqlite database Sqlite数据库
  • JAVA 11 JAVA 11

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_TMPDIRTMPDIR用于类似 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.

相关问题 如何在Java中创建临时文件夹并在其中添加文件 - how to create temporary folder in java and add files inside it 如何在 Java 中创建一个临时目录/文件夹? - How to create a temporary directory/folder in Java? 如何使用zip文件夹创建临时文件夹 - How to create temporary folder with zip folder inside 如何使用GZIPINPUT / GZIPOUTPUT流将.gz文件下载到temp文件夹 - how to download .gz files to the temp folder using GZIPINPUT/GZIPOUTPUT stream 将文件保存到临时文件夹 - Saving files to temp folder Java-如何在我的项目文件所在的文件夹中重新引用Sqlite数据库? - Java-How Do I Rerefrence Sqlite Database in the Same Folder With My Project Files? 在java中创建临时文件夹 - Creating temp Folder in java 如何使用 SQliteOpenhelper :android 项目将 SQLite 数据库路径更改为不同的文件夹(在应用程序目录中) - How to change SQLite database path to different folder (in application directory) using SQliteOpenhelper :android project 爪哇蔚来| 路径和文件 | 如何使用从其他对象获取的自定义名称创建自定义文件和文件夹? - Java NIO | Paths & Files | How to create custom file and folder with custom name fetched from other object? 需要帮助以在特定文件夹中创建sqlite数据库 - Need help to create an sqlite database at a particular folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM