5

I wish to have read only and write connections for sqlite, when I open a write connection, I wish it to have an exclusive lock. This 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 have also tried setting the properties directly, rather than using the Sqlite jdbc SQLiteConfig class

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

Any suggestions?

1 Answer 1

3

The only way that I was able to personally make it work is by executing a query on the DB itself like this :

conn.createStatement().execute("PRAGMA locking_mode = EXCLUSIVE");
Sign up to request clarification or add additional context in comments.

1 Comment

Can it be combined with journal_mode=WAL? I get a SQLITE_BUSY error if I try to set both, regardeless of the order

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.