i have a very terrible problem now with SQLite database. I used it for an app development and it runs well without no exception errors on my computer. but when I run the app on another pc, I get a pop-up saying SQLite database is locked..i click on it many times before the app opens and it works fine. but if I close the app and attempt to open it again, the same 'sqlite database lock exception pops up' and its very disturbing. please how do I solve this problem. thanks
Asked
Active
Viewed 29 times
3 Answers
0
That probably means the handle for the database was not closed/disposed correctly.
You need to call conn.close();
when the application is going to be closed, see this answer

Marcin Gordziejewski
- 124
- 1
- 8
-
well the funny thing is I compiled it into setup and installed it on my computer.. and when I run it, I get no errors at all. everything flows well. the problem is when I install it on another pc...the lock exception appears..@Maicin_Gordziejewski. – Rodney Nart Nov 29 '17 at 20:59
-
You have to provide the code for the database handling part of your program. Can't help without it. – Marcin Gordziejewski Nov 29 '17 at 21:00
-
I have provided the code for the database handling @Marcin_Gordziejewski.. please where did I go wrong – Rodney Nart Nov 29 '17 at 21:09
-
Changed my answer – Marcin Gordziejewski Nov 29 '17 at 21:12
-
hmm ok.. am a bit new with coding. please how do I close the conn – Rodney Nart Nov 29 '17 at 21:15
-
By using the `conn.close();` function. – Marcin Gordziejewski Nov 29 '17 at 21:18
-
i tried that already but i get this :'non static variable conn cannot be referenced from a static context'@ Marcin – Rodney Nart Nov 29 '17 at 21:21
-
conn.close(); is not working on the database handler. does this mean I should close every connection in all query statements in the app? – Rodney Nart Nov 29 '17 at 22:05
0
public static Connection connectDB(){
try{
String sys =System.getProperty("user.home");
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:"+sys+"\\Desktop\\hyper-DB\\database.sqlite3");
return conn;
}catch(ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
please the above code is for the SQLite connection.. please what haven't I done right.

Rodney Nart
- 121
- 11
-
When your program gets a signal that it is going to be closed, you need to close the `conn` – Marcin Gordziejewski Nov 29 '17 at 21:09