java.sql.SQLTransactionRollbackException:在请求的时间内无法获得锁

时间:2018-08-31 17:23:41

标签: java jdbc

标题是我遇到的问题。有什么想法可以解决这个问题吗?过去5个小时,我一直在玩这个游戏。

这是我的代码,如果您有任何疑问,请告诉我。

* ID是全局变量

 String UpdateFirst = txtFirstSettings.getText();
        String UpdateLast = txtLastSettings.getText();
        String UpdateSex = txtSexSettings.getText();
        String UpdateJobTitle = txtJobTitleSettings.getText();
        String UpdateEmail = txtEmailSettings.getText();
        String UpdateLawFirm = txtLawFirmSettings.getText();
        try {
            String host = "jdbc:derby://localhost:1527/Lawyers";
            String uName = "spyfire14";
            String uPass = "spyfire14";
            Connection con = DriverManager.getConnection(host, uName, uPass);

            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                   ResultSet.CONCUR_UPDATABLE);
            String sql = "SELECT * FROM LAWYERLISTS WHERE ID = " + ID;
            ResultSet rs = stmt.executeQuery(sql);

                rs.first();
                    rs.updateString("FIRST_NAME", UpdateFirst);
                    rs.updateString("LAST_NAME", UpdateLast);
                    rs.updateString("SEX", UpdateSex);
                    rs.updateString("JOB_TITLE", UpdateJobTitle);
                    rs.updateString("EMAIL", UpdateEmail);
                    //Include a confirmation
                    rs.updateRow();
                    rs.close();
                    stmt.close();
                    System.out.println(UpdateEmail);
                    System.out.println(rs.getString("EMAIL"));

            } catch (SQLException ex) {
                Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
            }

这是完整的异常代码:

Aug 31, 2018 5:18:10 PM dashboardapp.Home btnSaveSettingsMouseReleased
SEVERE: null
java.sql.SQLTransactionRollbackException: A lock could not be obtained within the time requested
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.client.am.ResultSet.updateRow(Unknown Source)
    at dashboardapp.Home.btnSaveSettingsMouseReleased(Home.java:1851)
    at dashboardapp.Home.access$600(Home.java:46)
    at dashboardapp.Home$6.mouseReleased(Home.java:365)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2238)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2296)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4897)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4475)
    at java.awt.Container.dispatchEventImpl(Container.java:2282)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: org.apache.derby.client.am.SqlException: A lock could not be obtained within the time requested
    at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
    at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
    at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
    at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
    at org.apache.derby.client.am.ResultSet.readUpdateRow(Unknown Source)
    at org.apache.derby.client.am.ResultSet.update(Unknown Source)
    at org.apache.derby.client.am.ResultSet.updateRowX(Unknown Source)
    ... 36 more

编辑:我按照评论的意思做了,我知道没有得到警告,但是它实际上并没有改变数据库

Connection con = DriverManager.getConnection(host, uName, uPass);
            con.setAutoCommit(false);
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                   ResultSet.CONCUR_UPDATABLE);
            String sql = "SELECT * FROM LAWYERLISTS WHERE ID = " + ID;
            ResultSet rs = stmt.executeQuery(sql);

                rs.first();
                    rs.updateString("FIRST_NAME", UpdateFirst);
                    rs.updateString("LAST_NAME", UpdateLast);
                    rs.updateString("SEX", UpdateSex);
                    rs.updateString("JOB_TITLE", UpdateJobTitle);
                    rs.updateString("EMAIL", UpdateEmail);
                    con.commit();
                    //Include a confirmation
                    //rs.updateRow();
                    rs.close();
                    stmt.close();

0 个答案:

没有答案