I have a large database that I want to open in read-only mode... I'm using SQLiteJDBC and am not sure what to use to get it to work as read-only.
Can anyone help?
Test demonstrate how to set connection to be read-only:
SQLiteConfig config = new SQLiteConfig();
config.setReadOnly(true);
Connection conn = DriverManager.getConnection("jdbc:sqlite:sample.db",
config.toProperties());
Try this.
Properties config = new Properties();
config.setProperty("open_mode", "1"); //1 == readonly
Connection conn = DriverManager.getConnection("jdbc:sqlite:sample.db", config);
Just want to add that when using HikariCP, you need two datasource properties:
readOnly=true
dataSource.open_mode=1
I had a slightly different scenario, but the same issue. If you have a spring boot service using Hikari you need to provide 2 configuration settings in your application.properties
spring.datasource.url=jdbc:sqlite:myDatabase.db?open_mode=1
spring.datasource.hikari.read-only=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With