我已经创建了一个使用sqlite数据库的java软件。SQLITE_BUSY数据库被锁定java
值java.sql.SQLException:[SQLITE_BUSY]数据库文件被锁定(数据库是整个数据库后,但运行的应用程序,我reveiving以下消息(从try catch块)的一段时间,工程进展顺利锁)
我已经解决了我的问题,每当异常上升时关闭软件。但是,有没有办法关闭我的数据库,以免每次关闭软件?
我已经有足够的查询但是我始终概率出现在一个特定的点:
try {
String query = "select * from StudentsSession where userId=? and course=? and level=?";
PreparedStatement pst = connectionUsers.prepareStatement(query);
pst.setString(1, saveUser.getText());
pst.setString(2, textSubjectQTest);
st.setString(3, showCurrentLevelLabel.getText());
ResultSet rs = pst.executeQuery();
while (rs.next()) {
count = count + 1;
}
pst.close();
rs.close();
} catch (Exception a) {
System.out.println(a);
}
try {
String countS, tmpS;
countS = String.valueOf(count);
sessionId.setText(countS);
long unixTime = System.currentTimeMillis()/1000L;
tmpS = String.valueOf(unixTime);
date.setText(tmpS);
course.setText(textSubjectQTest);
String query = "insert into StudentsSession (userId,date,course,level,trial,score) values (?,?,?,?,?,-1)";
PreparedStatement pst = connectionUsers.prepareStatement(query);
pst.setString(1, saveUser.getText());
pst.setString(2, tmpS);
pst.setString(3, textSubjectQTest);
pst.setString(4, showCurrentLevelLabel.getText());
pst.setString(5, countS);
pst.executeUpdate();
pst.close();
} catch (Exception a) {
System.out.println(a);
System.exit(0);
}
String file1 = "";
ResultSet ts4;
try {
sessionId3 = "";
String query3 = "select * from studentssession where userid = ? and course = ? and level = ?";
PreparedStatement pst__1 = connectionUsers.prepareStatement(query3);
pst__1.setString(1, saveUser.getText());
pst__1.setString(2, textSubjectQTest);
pst__1.setString(3, showCurrentLevelLabel.getText());
ts4 = pst__1.executeQuery();
while (ts4.next()) {
sessionId3 = ts4.getString("sessionId");
}
pst__1.close();
ts4.close();
obj = new CaptureVideoFromWebCamera();
file1 = "videos/" + userTextFieldS.getText();
file1 = file1 + "_" + sessionId3;
file1 = file1 + ".wmv";
obj.start(file1);
} catch (Exception e4) {
e4.getCause();
}
有时这种代码上升例外。
SQlite对于小型本地应用程序很有用,在这种情况下,Singleton足以防止锁定。如果你的应用程序中有多个线程,那将解决你的问题。我会说你忘了在某处关闭你的连接。我用它在一个旧的应用程序没有这种类型的问题。 – AxelH
看来,当我试图访问特定的表时,会出现此错误。所以我的问题是,我有一个查询语句,我从来没有关闭它的地方? –
我的问题出现在每次具体的查询中,我不知道为什么! –