Sqlite jdbc setJournalMode

I run my first SQLite tests (with JDBC) as a clean database. Since I need very fast inserts, I tried to adjust the configuration accordingly. I could find out that the code below does not work only when setting up for JournalMode. See the method shown below. The variables con and isConnected are defined as vars classes and are not shown here.

thanks a lot

Rolf

public Boolean connect() { try { Class.forName("org.sqlite.JDBC"); // sqlitejdbc_3.7.2 // Set all pragmas SQLiteConfig config = new SQLiteConfig(); // This statement (JournalMode setting) causes a fail // Without that statement the connection can be established // ==> java.sql.BatchUpdateException: batch entry 0: query returns results config.setJournalMode(JournalMode.MEMORY); config.setTempStore(TempStore.MEMORY); config.setSynchronous(SynchronousMode.OFF); config.enforceForeignKeys(false); config.enableCountChanges(false); con = DriverManager.getConnection("jdbc:sqlite::memory:", config.toProperties()); isConnected = true ; return true ; } catch (Exception e) { LogMessages.instance().print(0, LogMessages.MSG_SEVERITY.ERROR, e.getMessage() + "\n"); e.printStackTrace() ; return false ; } } 
+4
source share
1 answer

I have the same problem, but there is another way to disable it. After opening the connection, you can run this query: PRAGMA journal_mode = MEMORY;

0
source

Source: https://habr.com/ru/post/1479759/


All Articles