Opening database connection with the SQLITE_OPEN_N

2020-07-27 02:43发布

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:");

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

标签: java sqlite jdbc
1条回答
乱世女痞
2楼-- · 2020-07-27 03:25

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() //
);
查看更多
登录 后发表回答