GOXR3PLUS
GOXR3PLUS

Reputation: 7255

SQLite quirky database table lock

I am using sqlite as the database of an application.It works fine on everything but when i am going to delete a table from the database then it throws this error using [https://bitbucket.org/xerial/sqlite-jdbc]:

Error

java.sql.SQLException: [SQLITE_LOCKED]  A table in the database is locked (database table is locked)

I am using no-auto-commit-mode so before deleting the table i had already committed.Why this is happening?

A possible solution is to close the connection and re-open it but this can't be done because other actions are taking place simultanesouly.

**

Solution is:------------------------

**

I was counting the rows of a table into a thread using:

connection1.createStatement().executeQuery("SELECT COUNT(*) FROM LIBRARIES;").getInt(1);

but this returns a result set which was never closed so the database table was forever locked!!

Upvotes: 0

Views: 279

Answers (1)

CL.
CL.

Reputation: 180080

This is a FAQ. It is not possible for multiple programs/threads to access the database at the same time when one is writing.

You should set a timeout to allow your thread to wait for others to finish.

Upvotes: 1

Related Questions