3

I want to use the Write-Ahead Logging feature of SQLite in a j2se program. Please help me with a java implemention example.

Paul Sonier
  • 38,903
  • 3
  • 77
  • 117
Vivek
  • 11,938
  • 19
  • 92
  • 127

1 Answers1

4

You need to execute a Sqlite specific command (just like you'd execute other SQL queries):

pragma journal_mode=wal

For the specifics of using this pragma, please read http://www.sqlite.org/pragma.html#pragma_journal_mode

Here are some highlights:

  • Your Sqlite library must be >= 3.7.0.
  • This journal_mode is persistent (or sticky), ie you'll need to disable it explicitly if you want to access your database with a < 3.7.0 Sqlite.
  • Note that this command *will* return a result set -- a detail missed in the Xerial SQLite JDBC wrapper, as reported here: http://code.google.com/p/sqlite-jdbc/issues/detail?id=7 – seh Jul 11 '11 at 22:46
  • @sixfeetsix: Does this means that i have to write a statement like stmt.execute("pragma journal_mode=WAL"); in my java program ? But i don't see any increase in performance with this statement. – Vivek Jul 15 '11 at 18:36
  • 1
    @sam: yes, execute the statement as any other sql; as seh mentions, this pragma is particular as it returns a result set with the resulting journal_mode, so please make sure you get "wal". If you do get "wal", then I guess using WAL wasn't what ou needed to do to increase performance. If you want help with that, I suggest you create a new question where you'll describe what it is that is slow by providing the enough context to allow the community to help you (eg how much time a query takes, what is the query, what is/are the table structure(s), a sample of the typical records, etc.) –  Jul 15 '11 at 18:55
  • @sixfeetsix: The problem is "pragma journal_mode=WAL" is supported by SQLite 3.7 but there are no compatible jdbc drivers for this new version and the default mode does not changing through older drivers. – Vivek Jul 15 '11 at 20:40
  • 1
    @sam: doesn't the workaround in http://code.google.com/p/sqlite-jdbc/issues/detail?id=7 work for you? –  Jul 15 '11 at 20:48