例外:数据库已被锁定?

时间:2016-05-17 10:19:19

标签: java sql database sqlite jframe

我想清理jTable和数据库上的数据。所以我有一个干净的按钮。当我运行我的代码时,我点击了这个按钮。我正在查看错误消息。

我不明白导致这个例外:

java.sql.SqlException:[SQLITE_BUSY]数据库文件已锁定(数据库已锁定)

我的代码是:

   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);
    }
}                     

我的delPerson代码是:

    public void delPerson(String id) throws Exception
{
    String q = String.format("delete from passengerInfo where CustomerID = %s", id);
    conn.createStatement().execute(q);
}

0 个答案:

没有答案
相关问题