executeUpdate的问题!

vibra 2003-03-31 12:30:26
我在bean中写了一个executeUpdate的方法,只做一次更新就很正常,但如果连续
更新就出问题了
String update1="update libbook set bdate='"+bdatetime+"' where cardid='"+cardid+"' and bookctl='"+bookctl+"'";
connBeanId.executeUpdate(update1);
String update2="update libbook set rdate='"+rdatetime+"' where cardid='"+cardid+"' and bookctl='"+bookctl+"'";
connBeanId.executeUpdate(update2);
只能更新前面那个
后面那个就更新不了,抛出异常说general error
这是什么回事?
...全文
554 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
moumouren 2003-03-31
  • 打赏
  • 举报
回复
请确认第一条update的语句是否已经commit,还有,两个update语句是否同用一个connection
moumouren 2003-03-31
  • 打赏
  • 举报
回复
请确认第一条update的语句是否已经update,还有两个update语句是否同用一个connection
skysaint 2003-03-31
  • 打赏
  • 举报
回复

stmt.addBatch(string sql)
添加多条SQL语句一同提交
stmt.excuteBatch()
这样也可以避免频繁与数据库交互
skysaint 2003-03-31
  • 打赏
  • 举报
回复
不要创建几个stmt,一起用第一个就行了
vibra 2003-03-31
  • 打赏
  • 举报
回复
感谢大家,问题已经解决,原来我在bean中的executeUpdate的方法中把conn关掉了。
不过又有新问题!我尝试用addbatch和executeBatch的方法时好像只能执行最靠近executbatch的那个addbatch,是什么回事?
在bean中的代码如下:
public void addBatch(String sql) {
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.addBatch(sql);
}
catch (SQLException ex) {
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}

public void executeBatch() {

try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);


stmt.executeBatch();

}
catch (SQLException ex) {
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}

skysaint 2003-03-31
  • 打赏
  • 举报
回复
connection.commit()
vibra 2003-03-31
  • 打赏
  • 举报
回复
to moumouren(某某人)
如何commit,用什么语句?
peacock_king 2003-03-31
  • 打赏
  • 举报
回复
上一条语句可能未执行完毕,改为:

Statement stmt=con.createStatement();

String update1="update libbook set bdate='"+bdatetime+"' where cardid='"+cardid+"' and bookctl='"+bookctl+"'";

String update2="update libbook set rdate='"+rdatetime+"' where cardid='"+cardid+"' and bookctl='"+bookctl+"'";

stmt.addBatch(update1);
stmt.addBatch(update2);
stmt.executeBatch();

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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