public  static void SynchronizeRequiredData(Connection mConnection) throws DataAccessException {
        
        Statement oStatement = null;
        String  update=null;
        
        try {
        
        
            oStatement=mConnection.createStatement();
            update="update topotreenodetable set name= (select name from toponodetable where originid=topotreenodetable.originid) ,type= (select type from toponodetable where originid=topotreenodetable.originid),state= (select state from toponodetable where originid=topotreenodetable.originid)";
            debug.info("execute SQL: "+update);
            oStatement.executeUpdate(update);
            
            update="update topotreenodetable set name= (select name from toporoottable where originid=topotreenodetable.originid) ,type= (select type from toporoottable where originid=topotreenodetable.originid),state= (select state from toporoottable where originid=topotreenodetable.originid)";
            debug.info("execute SQL: "+update);
            oStatement.executeUpdate(update);
            
            update="update topotreenodetable set name= (select name from topogrouptable where originid=topotreenodetable.originid) ,type= (select type from topogrouptable where originid=topotreenodetable.originid),state= (select state from topogrouptable where originid=topotreenodetable.originid)";
            debug.info("execute SQL: "+update);
            oStatement.executeUpdate(update);  
        } catch (SQLException e) {
            DataAccessException dae = new DataAccessException(e, GeneralUtilService.SERVER_GENERIC_ERROR, "SQL operate fail: "+update);
            debug.info("Get DB data compute result exception.", dae);
            throw dae;
        } finally {            
            if (oStatement != null) {
                try {
                    oStatement.close();
                } catch (SQLException ignore) {
                }
                oStatement = null;
            }
        }        
    }
调用此方法为:
UserTransaction ut = this.mSessionContext.getUserTransaction();
ut.begin();
SynchronizeRequiredData(this.getConnection);
ut.commit();
为什么只有最后一个update能够执行成功,,如果屏蔽其中两中,留一任意一个,都能执行成功呢?

解决方案 »

  1.   

    oStatement.executeUpdate(update);  
    换成
    oStatement.executeAutoUpdate(update);  
      

  2.   

    ps = mConnection.prepareStatement(update);
    rs = ps.executeUpdate();
    试一下;
      

  3.   

    声明一个Statement之后
    多次使用  int 变量执行 executeUpdate()即可
      

  4.   

    多次使用  int 变量执行 executeUpdate()即可 
    int i = oStatement.executeUpdate();这样么?
      

  5.   

    你执行了三个executeUpdate,但是执行的都是数据库中的同一行,所以你只看到了最后一个执行了。