DELETE查询在Java中的sqlite中不起作用

时间:2017-03-25 12:22:05

标签: java

这是我的功能,每次运行时都会出错

public static void deletePreviousInvoice(int invoice_id)
{
    try {
        String sql = "DELETE FROM INVOICE WHERE INVOICE_NO = ?";
        try (PreparedStatement s = con.prepareStatement(sql)) {
            s.setInt(1, invoice_id);
            s.executeQuery();
        }
    } catch (SQLException ex) {
        Logger.getLogger(GENERATE_METHODS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

错误是这个自动提交设置为true我的所有插入查询和选择查询都在运行但是每次运行此数据库时锁定查询都不起作用

Mar 25, 2017 5:04:01 PM GENERATE_INOVICE.GENERATE_METHODS deletePreviousInvoice
        SEVERE: null
        java.sql.SQLException: database locked
            at org.sqlite.DB.execute(DB.java:270)
            at org.sqlite.PrepStmt.execute(PrepStmt.java:57)
            at GENERATE_INOVICE.GENERATE_METHODS.deletePreviousInvoice(GENERATE_METHODS.java:224)
            at GENERATE_INOVICE.GENERATE_INVOICE.jButton_invoiceActionPerformed(GENERATE_INVOICE.java:815)
            at GENERATE_INOVICE.GENERATE_INVOICE.access$1100(GENERATE_INVOICE.java:27)
            at GENERATE_INOVICE.GENERATE_INVOICE$14.actionPerformed(GENERATE_INVOICE.java:659)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
            at java.awt.Component.processMouseEvent(Component.java:6525)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
            at java.awt.Component.processEvent(Component.java:6290)
            at java.awt.Container.processEvent(Container.java:2234)
            at java.awt.Component.dispatchEventImpl(Component.java:4881)
            at java.awt.Container.dispatchEventImpl(Container.java:2292)
            at java.awt.Component.dispatchEvent(Component.java:4703)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
            at java.awt.Container.dispatchEventImpl(Container.java:2278)
            at java.awt.Window.dispatchEventImpl(Window.java:2750)
            at java.awt.Component.dispatchEvent(Component.java:4703)
            at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
            at java.awt.EventQueue.access$500(EventQueue.java:97)
            at java.awt.EventQueue$3.run(EventQueue.java:702)
            at java.awt.EventQueue$3.run(EventQueue.java:696)

1 个答案:

答案 0 :(得分:0)

要添加上面的答案,会产生错误:

java.sql.SQLException: database locked

可能是因为您之前进行过查询后没有关闭连接。