views:

132

answers:

2

Hi...

I'm trying to run several instances of a program accessing a sqlite database in java (always the same file) and actually I don't know whether it's possible or not that several jobs access the same database....

+1  A: 

Trying to access a single SQLite database from different processes is perfectly fine (whatever language you are using) as SQLite will take care to ensure proper locking. However, please note that SQLite doesn't handle lock contention particularly well - so if you have multiple processes constantly accessing the database at the same time, you might want to consider a different database or using a single server for accessing the database.

cmeerw
I added a FileLock on the sqlite DB and it seems to avoid this exception.The problem stems from the driver since when it tries to insert something and sqlite holds a lock, it raises an exception... So I just lock the insertion...
LB
+1  A: 

SQLite will, in fact, take care of the locking, and you shouldn't expect concurrency issues. Not any that originate in SQLite, in any case.

However, do note that this solution is totally not scalable. If that is an issue that concerns your application you should check out other DB solutions.

Yuval A
I wasn't supposed to do it in a concurrent environment. Switching to another DB solution is the next step..
LB