本文介绍了在Java中使用SQLITE_OPEN_NOMUTEX标志打开数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 Sqlite文档后,我想确保在运行时连接到数据库处于正确的模式.

After reading the Sqlite documentation I wanted to make sure that by run-time the connection to the database is in the correct mode.

Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:");

我正在使用Sqlite JDBC驱动程序.如何添加SQLITE_OPEN_NOMUTEX标志?

I'm using the Sqlite JDBC driver. How can I add the SQLITE_OPEN_NOMUTEX flag?

推荐答案

在我有些疑问之后,为什么在C中看起来如此简单,而在Java中却不可行,这里可能是解决方案:

After I had some doubts why in C it looks so easy and in Java it should not possible, here probably the solution:

Class.forName("org.sqlite.JDBC");

SQLiteConfig config = new SQLiteConfig();
config.setOpenMode(SQLiteOpenMode.READWRITE);
config.setOpenMode(SQLiteOpenMode.CREATE);
config.setOpenMode(SQLiteOpenMode.NOMUTEX);

Connection connection = DriverManager.getConnection( //
              "jdbc:sqlite::memory:", //
              config.toProperties() //
);

这篇关于在Java中使用SQLITE_OPEN_NOMUTEX标志打开数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:45