Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jakarta ee 执行XA事务时DB2死锁问题SQLCODE=-911,SQLERRMC=68_Jakarta Ee_Jdbc_Transactions_Db2_Jndi - Fatal编程技术网

Jakarta ee 执行XA事务时DB2死锁问题SQLCODE=-911,SQLERRMC=68

Jakarta ee 执行XA事务时DB2死锁问题SQLCODE=-911,SQLERRMC=68,jakarta-ee,jdbc,transactions,db2,jndi,Jakarta Ee,Jdbc,Transactions,Db2,Jndi,我正在编写一个示例jdbc代码,它试图实现两阶段提交。有两个数据源,都是DB2和XA兼容的。创建了两个独立的jdbc连接。我使用Atomikos作为TM。使用这些连接,可以对数据源进行更新。但是,更新查询未执行,并返回-911错误。我无法找出僵局发生的原因和地点。而且,这两个连接都是独立的,不相关的,那么为什么会出现死锁/超时呢 .... try{ //Get the datasource connection using jndi custom class

我正在编写一个示例jdbc代码,它试图实现两阶段提交。有两个数据源,都是DB2和XA兼容的。创建了两个独立的jdbc连接。我使用Atomikos作为TM。使用这些连接,可以对数据源进行更新。但是,更新查询未执行,并返回-911错误。我无法找出僵局发生的原因和地点。而且,这两个连接都是独立的,不相关的,那么为什么会出现死锁/超时呢

....   
     try{

        //Get the datasource connection using jndi custom class

        JndiConn jcon1 = new JndiConn("jdbc/myDatasource1");
        JndiConn jcon2 = new JndiConn("jdbc/myDatasource2");
        UserTransactionImpl utx = new UserTransactionImpl();
        try{
            //Begin transaction             
            utx.begin();

            //Get the connection from the DB
            conn1 = jcon1.ds.getConnection();
            conn2 = jcon2.ds.getConnection();

            //Reading the data from the form
            int frmAccntNum = Integer.parseInt(req.getParameter("frmAccnt"));
            int toAccntNum = Integer.parseInt(req.getParameter("toAccnt"));
            int amt = Integer.parseInt(req.getParameter("amt"));

            //Create a statement from the Connection

            try{
                String selectQuery = "select AccountNumber, Balance from Accounts where AccountNumber =? with ur";
                PreparedStatement stmt = conn1.prepareStatement(selectQuery);
                stmt.setInt(1,frmAccntNum);
                ResultSet rs = stmt.executeQuery();
                rs.next();
                Account frmAccnt = new Account(rs.getInt(1),rs.getInt(2));
                int tempBal = frmAccnt.getBalance();

                PreparedStatement stmt2 = conn2.prepareStatement(selectQuery);
                stmt2.setInt(1, toAccntNum);
                ResultSet rs1 = stmt.executeQuery();
                rs1.next();
                Account toAccnt = new Account(rs1.getInt(1),rs1.getInt(2));
                int tempBal2 = toAccnt.getBalance();

                }
                Operations t1 = new Operations();
                if(t1.checkAmt(frmAccnt,amt)){
                    t1.Withdraw(frmAccnt, amt);
                    t1.Deposit(toAccnt, amt);
                }


                String updateQuery = "update Accounts set Balance = ? where AccountNumber= ? with ur";
                stmt = conn1.prepareStatement(updateQuery);
                stmt.setInt(1, frmAccnt.getBalance());
                stmt.setInt(2,frmAccnt.getAccountNumber());
                stmt.executeUpdate();

                stmt2 = conn2.prepareStatement(updateQuery);
                stmt2.setInt(1, toAccnt.getBalance());
                stmt2.setInt(2,toAccnt.getAccountNumber());
                stmt2.executeUpdate();
                //int r1 = stmt.executeUpdate("update Accounts set Balance = "+frmAccnt.getBalance()+"where AccountNumber="+frmAccnt.getAccountNumber());

                stmt.close();
                stmt2.close();

            }catch(SQLException sq){
                System.out.println("Setting Rollback true");
                sq.printStackTrace();
                rollback = true;
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }finally{
            if(!rollback){
                try{
                    utx.commit();
                }catch(Exception e){
                    System.out.println("Commit Exception");
                    e.printStackTrace();
                    rollback = true;
                    try {
                        utx.rollback();
                    } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } 
                }
            }
            else{
                try {
                    utx.rollback();
                } catch (Exception e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                } 
            }
            try {
                conn1.close();
                conn2.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }   
    }catch(NamingException nme){
        nme.printStackTrace();
    }
这是因为:

ResultSet rs1 = stmt.executeQuery();
你想要

ResultSet rs1 = stmt2.executeQuery();

在打开rs1之前尝试关闭rs(我认为是rs.close()),在发出update语句之前关闭rs1。这有用吗?听起来好像有些东西没有关闭。我尝试关闭rs和rs1,结果仍然是死锁。啊…是的..解决了它。天哪,错过了这么愚蠢的事情:(Thnks!!