繁体   English   中英

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

[英]How to change sqlite database to create temporary files in any other folder instead of temp folder using JAVA?

我在我的 JAVA 应用程序中使用 SQLite 数据库,在该应用程序中,我在运行时创建数据库,然后创建表并执行不同的 DB 操作,因为 SQLite 必须创建其临时文件的目录,目前在我的 windows 操作系统环境 SQLite 正在 TEMP 文件夹中创建文件,我需要更改 C 驱动器以外的任何其他位置的文件夹。 我尝试过以下操作

  1. 在以下问题中更改TEMPTMP的环境变量值如何更改 sqlite 创建 etilqs 文件的临时文件夹?
  2. 添加以下问题设置 sqlite 临时存储目录中提到的新环境变量SQLITE_TMPDIRTMPDIR
  3. 我根据以下 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() } }

我还在 SQLite 浏览器中打开我的数据库文件并执行以下查询PRAGMA temp_store_directory = 'D:\SQLite-TMP'; 但仍然 SQLite 在 TEMP 文件夹中创建临时文件 我想将临时文件的位置更改为D:\SQLite-TMP这个文件夹。 任何人都可以帮助我,因为我陷入了这个问题,请让我知道如何设置全局变量sqlite3_temp_directory因为我不明白如何从官方文档中设置它谢谢。

我的环境

  • Windows 10
  • Sqlite数据库
  • JAVA 11

首先,pragma temp_store_directory已被弃用(请参阅this ),因此可能不再有效。

其次, SQLITE_TMPDIRTMPDIR用于类似 unix 的操作系统,看起来您使用的是 Windows。

所以我会尝试设置全局变量sqlite3_temp_directory 如底部所述。

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM