求教一个JDBC的关于同一个Statement多次更新的问题!
sarcs 2008-11-17 07:48:54 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能够执行成功,,如果屏蔽其中两中,留一任意一个,都能执行成功呢?