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能够执行成功,,如果屏蔽其中两中,留一任意一个,都能执行成功呢?
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能够执行成功,,如果屏蔽其中两中,留一任意一个,都能执行成功呢?
换成
oStatement.executeAutoUpdate(update);
rs = ps.executeUpdate();
试一下;
多次使用 int 变量执行 executeUpdate()即可
int i = oStatement.executeUpdate();这样么?