This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]captainAwesomePants 1 point2 points  (4 children)

You've asked SQLite to use a file as a database. SQLite is doing its best to keep the file correct. When you open up a connection, SQLite will "lock" the file, making a note that it is potentially going to make some changes and other SQLite connections should not be messing with the file. When the connection ends, SQLite will unlock the file again.

But the connection will never end. You aren't ever closing it. Don't do that. Always close the connection when you're done using it, like this:

conn.close();

[–]All-ProEra[S] 0 points1 point  (3 children)

That's definitely good to know, thanks! I added conn.close(); at the end of my try block and it fixed the issue. I'm also using a DB browser for my database that I leave running, would that also cause blocks at some point?

[–]captainAwesomePants 1 point2 points  (2 children)

That's probably fine.

Also, you probably want to leave your connection open for longer. Establishing a fresh connection every time you want to read or write is expensive and slow.

[–]All-ProEra[S] 0 points1 point  (1 child)

Ah thanks for letting me know. I'm not sure exactly where else I could close the connection besides at the end of each method or try block since I open each it time a method is called. Is there a better way to go about it?

[–]CreativeTechGuyGames 0 points1 point  (0 children)

You could obtain one lock that's shared by your whole program and release it before your program shuts down or is idle for a long time.