0

I want to clean data on jTable and database. So i have a Clean Button. I clicked this button when i was run my codes. I am seing Error Message.

I don't understand cause this exception:

java.sql.SqlException : [SQLITE_BUSY] The Database file is locked(database is locked)

My codes are :

   private void btnCleanActionPerformed(java.awt.event.ActionEvent evt) {                                       

    int ndxs[] = jTable1.getSelectedRows();
    if (ndxs.length == 0) {
        show("Error", "You can chose row", JOptionPane.WARNING_MESSAGE);
        return;
    }
    try {

        ArrayList<String> idList = new ArrayList<>();
        for (int i = 0; i < ndxs.length; i++) {
            String id = jTable1.getValueAt(ndxs[i], 0).toString();
            idList.add(id);
        }

        if (idList.size() == 1) {
            db.delPerson(idList.get(0));
        } else {
            String sql =db.toSQL(
                    "delete from passengerInfo where CustomerID in %s", idList.toString().replace("[", "(")
                    .replace("]", ")"));

            //System.out.println(sql);
            db.exec(sql);
        }

        refreshTable();

        show("Result", "Cleaned", JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
        show("Error", "Didn't clean : \n\n" + e, JOptionPane.ERROR_MESSAGE);
    }
}                     

My delPerson codes are :

    public void delPerson(String id) throws Exception
{
    String q = String.format("delete from passengerInfo where CustomerID = %s", id);
    conn.createStatement().execute(q);
}
Tuğba
  • 1
  • 1
  • Have you closed the previously open `Connection`/`Statement`s? – MadProgrammer May 17 '16 at 10:25
  • i have DB(database) class and Customer class. Connection and Statement are in DB class.They aren't in Customer Class. btnCleanActionPerformed button is in Customer class. Connection and Statement open in DB. But is it affect my Customer class ? – Tuğba May 17 '16 at 10:37
  • Look the answer here http://stackoverflow.com/questions/8559623/sqlite-busy-the-database-file-is-locked-database-is-locked-in-wicket – Abylay Sabirgaliyev May 17 '16 at 11:08
  • Of course it does, they are connections to the sane database/file – MadProgrammer May 17 '16 at 11:20

0 Answers0