求教一个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能够执行成功,,如果屏蔽其中两中,留一任意一个,都能执行成功呢?
...全文
303 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yixiangtiankai 2008-11-18
  • 打赏
  • 举报
回复
你执行了三个executeUpdate,但是执行的都是数据库中的同一行,所以你只看到了最后一个执行了。
sarcs 2008-11-18
  • 打赏
  • 举报
回复
多次使用 int 变量执行 executeUpdate()即可
int i = oStatement.executeUpdate();这样么?
lihan6415151528 2008-11-17
  • 打赏
  • 举报
回复
声明一个Statement之后
多次使用 int 变量执行 executeUpdate()即可
bao0437 2008-11-17
  • 打赏
  • 举报
回复
ps = mConnection.prepareStatement(update);
rs = ps.executeUpdate();
试一下;
bao0437 2008-11-17
  • 打赏
  • 举报
回复
oStatement.executeUpdate(update);
换成
oStatement.executeAutoUpdate(update);

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧