Sunday, December 16, 2012

An effective solution to "java.sql.SQLException: [SQLITE_BUSY] The database file is locked (database is locked)"

Similar to links like:

http://stackoverflow.com/questions/7930139/android-database-locked
http://stackoverflow.com/questions/13891006/getting-sqlite-busy-database-file-is-locked-with-select-statements

The sqlite database is sometimes locked very long when trying to insert, delete or update data with a java program. I had read the posts above but found no definite and clear solution in these  answers. I had also tried the proposed solution shown in the video https://www.youtube.com/watch?v=o7dn0cLvb5o about "the database is locked problem" in vain.


But finally, I figured out a simple and effective way to circumvent this problem so that I can continue my coding. The solution is as follows:


1.Backup the database folder where the locked sqlite db is located.





 2. Use Unlocker to delete the locked .db file




Unlocker can be downloaded from 
http://www.emptyloop.com/unlocker/Unlocker1.9.1-x64.exe
in the webpage
http://www.emptyloop.com/unlocker/

3.Copy the backup .db file back to the directory of the deleted locked sqlite .db.



These three simple steps can effectively solve the problem of  "java.sql.SQLException: [SQLITE_BUSY]  The database file is locked (database is locked)." Try it to evade this problem if baffled by it for quite a long time.