我们使用java创建了一个与sqlite数据库连接的软件。一切正常。但是当我们按下按钮打开数据库时,我们收到一条消息,表明数据库已被锁定。
[SQLITE_BUSY] The database file is locked (database is locked)
所以我们根本不能使用它..错误的原因是什么?我们怎样才能解决它?
此代码适用于我们遇到问题的按钮:
String id_patient = id.getText();
int idd, idd1 = 0;
idd = Integer.valueOf(first011.a55); //first011.a55 = id_patient
Connection connection22;
Statement statement22, stat, statement44, statement2;
connection22 = null;
try {
connection22 = DriverManager.getConnection("jdbc:sqlite:D:\\workspace\\FAMRSOFTWARE\\dataessai.sqlite");
statement2 = connection22.createStatement();
statement2.setQueryTimeout(30);
statement22 = connection22.createStatement();
statement22.setQueryTimeout(30);
stat = connection22.createStatement();
stat.setQueryTimeout(30);
statement44 = connection22.createStatement();
statement44.setQueryTimeout(30);
//This is to take and use id_demand from an other table in database
ResultSet Resultat = statement22.executeQuery("SELECT * FROM demandes WHERE ID_patient =" + first011.a55);
while (Resultat.next()) {
String iddemande = Resultat.getString("ID_demande");
idd1 = Integer.valueOf(iddemande);
}
int i = 0;
int string;
String idanalyse;
while (i < tablee.getRowCount()) {
if (!(tablee.getValueAt(i, 0) == null)) {
statement22.executeUpdate("INSERT INTO datails (ID_demande, ID_analyse ) VALUES ('" + idd1 + "', '" + Integer.valueOf((String) tablee.getValueAt(i, 0)) + "')");
i++;
} else {
break;
}
}
i = 0;
while (i < tablee.getRowCount()) {
if (!(tablee.getValueAt(i, 0) == null)) {
ResultSet Resultat2 = statement44.executeQuery("SELECT * FROM parametres WHERE ID_analyse =" + tablee.getValueAt(i, 0));
while (Resultat2.next()) {
stat.executeUpdate("INSERT INTO fichetechnique (ID_patient, ID_parametre, ID_analyse ) VALUES ('" + id.getText() + "', '" + Resultat2.getString("ID_parametre") + "', '" + tablee.getValueAt(i, 0) + "')");
}
i++;
} else break;
}
statement2.executeUpdate("UPDATE demandes SET total = '" + apayer.getText() + "',versement = '" + v.getText() + "' WHERE ID_patient = " + first011.a55);
//statement2.executeUpdate("UPDATE demandes SET versement = '"+v.getText()+"' WHERE ID_patient = "+first011.a55);
JOptionPane.showMessageDialog(null, "Les Analyses de ce patient est enregistrer avec succès !! ");
} catch (SQLException e1) {
System.err.println(e1.getMessage());
}
setVisible(false);