Erik
Erik

Reputation: 5119

How to avoid sql exceptions when two java desktop applications uses same SQLite db

I see some answers about this but they do not point in my direction.

When writing to SQLite all concurrent reads/writes will throw an exception.
This is going to be a problem for my setup since i have:

java background service
java Desktop gui application

Both accessing the same SQLite on the same computer.
Is there some global Singelton setup to deal with this.

Any ides would be grate

Upvotes: 0

Views: 121

Answers (1)

Brendan Long
Brendan Long

Reputation: 54242

From the sqlite4java page:

Single-threaded model - each SQLite connection is confined to a single thread, all calls must come from that thread. Application may open several connections to the same database from different threads. Along with the Serializable isolation level from SQLite, this feature facilitates writing very clean and predictable code.

So you need to either:

  • Have a dedicated thread that talks to SQLite
  • Open a new connection for each thread

Upvotes: 1

Related Questions