Open Sqlite connection with exclusive lock in Java / Scala using SQlite JDBC library

I want to only have read and write connections for sqlite, when I open the connection for writing, I want it to have an exclusive lock. It looks like it should work

val config = new SQLiteConfig();
config.setLockingMode(org.sqlite.SQLiteConfig.LockingMode.EXCLUSIVE)

val connection = DriverManager.getConnection("jdbc:sqlite:" + this.getPath() +"\\" + this.dbName, config.toProperties)

but unfortunately I get an exception

Exception in thread "main" java.sql.BatchUpdateException: batch entry 0: query returns results

I also tried setting the properties directly, instead of using the SQLiteConfig Sqlite jdbc class

val prop = new Properties();
prop.setProperty("locking_mode", "EXCLUSIVE");

Any suggestions?

+5
source share
1 answer

The only way I was able to personally make it work was to execute the query in the database itself as follows:

conn.createStatement().execute("PRAGMA locking_mode = EXCLUSIVE");
+1
source

All Articles