org.sqlite.SQLiteException:[SQLITE_BUSY]数据库文件被锁定(数据库被锁定)

时间:2018-06-10 06:05:33

标签: java sqlite

所以我为我的最后一年项目开发了一个CRUD应用程序。我有几个能够创建 - 更新 - 删除的JFrame。当我单独运行JFrames时,它可以毫无问题地完成它的工作,即Create-Update-Delete。但是,当我作为一个整体运行应用程序(导出为可运行的JAR)时,我收到此错误:

[SQLITE_BUSY] The database file is locked (database is locked)

以下是详细信息:

Connection Successful!
Connection Successful!
Connection Successful!
org.sqlite.SQLiteException: [SQLITE_BUSY]  The database file is locked (database is locked)
    at org.sqlite.core.DB.newSQLException(DB.java:909)
    at org.sqlite.core.DB.newSQLException(DB.java:921)
    at org.sqlite.core.DB.execute(DB.java:822)
    at org.sqlite.core.DB.executeUpdate(DB.java:863)
    at org.sqlite.jdbc3.JDBC3PreparedStatement.executeUpdate(JDBC3PreparedStatement.java:99)
    at main.UsersGUI$2.actionPerformed(UsersGUI.java:177)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

这是我的代码:

JButton updateButton = new JButton("Update");
        updateButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    String id = userID.getText();
                    String name = empName.getText();
                    String surname = empSurname.getText();
                    String username = usernameField.getText();
                    String job = jobRoleField.getText();
                    String sup = supField.getText();
                    String pro = projectNamefield.getText();
                    String dept = deptField.getText();

                    String sql = "update employeesDetails set empName = '"+name+"', empSurname = '"+surname+"', username = '"+username+"', position = '"+job+"'"
                            + ", projectName = '"+pro+"', supID = '"+sup+"', department = '"+dept+"' where empID = '"+id+"'";
                    pst = con.prepareStatement(sql);
                    pst.executeUpdate();
                    JOptionPane.showMessageDialog(null, "Successfully Updated! Reload the table to see the changes made.", "Updated", JOptionPane.INFORMATION_MESSAGE);
                }catch(Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Oops, something went wrong while Updating : " + ex, "Error Updating", JOptionPane.ERROR_MESSAGE);
                }finally {
                    try {
                        pst.close();
                    } catch (SQLException e1) {
                        //ignored
                    }
                }
            }
        });

我做错了什么?任何帮助将非常感激!非常感谢。

0 个答案:

没有答案