最近发现执行数据库语句时executeQuery语句总是执行一行,剩下的就不执行了。为什么?
例如下面的代码 
 public void jButton1_actionPerformed(ActionEvent e) {
  try {
            Connection con=DriverManager.getConnection("jdbc:odbc:jjtz","sa","sa");
            toUpdate=con.createStatement();
rs=toUpdate.executeQuery("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+1);
            rs.next();
rs=toUpdate.executeQuery("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+2);
            rs.next();
}
catch......
.......
只执行了第一句
第二句就没执行。为什么?
为什么这是?
前辈们请指教。小弟感激不尽。

解决方案 »

  1.   

    第一个rs.next(); 后游标的位置变化了吧
    看后台log应该能看到错误吧
      

  2.   

    肯定是不执行啊。因为你就一个toUpdate啊。
    使用批处理吧。。
      

  3.   

    executeQuery 跟
    rs.next()
    都不这么用的,去看看帮助吧。 
      

  4.   

    toUpdate=con.createStatement(); 
    int upd = toUpdate.executeUpdate(".....这样
      

  5.   

    你写更新语句应该是用executeUpdate而不是executeQuery(),
    executeUpdate用于update ,delete 更新语句,而executeQuery用于select 等查询语句.
      

  6.   

    我的jbuilder里没有executeUpdate语句
    很强
      

  7.   

    我的jbuilder里没有executeUpdate语句
    很强
      

  8.   

    在得到一个toUpdate
    执行第二条
      

  9.   

    怎么会没executeUpdate()方法?这个应该是有的。
      

  10.   

    catch里面把错误打印出来只用execute()方法就可以了,不要用executeQuery()这是查询用的.
      

  11.   

    再写一个toUpdate2=con.createStatement(); 
      

  12.   

    rs=toUpdate.executeQuery("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+1); 
                rs.next(); 
    rs=toUpdate.executeQuery("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+2); 
                rs.next(); 改为int count1=toUpdate.executeUpdate("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+1); 
                rs.next(); 
    int count2=toUpdate.executeUpdate("update jjxyylb set ljsdshhjxjll=(select sum(sdshhjxjll1) from qtzxjllb) where ID="+2); 
                rs.next();