最近发现执行数据库语句时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......
.......
只执行了第一句
第二句就没执行。为什么?
为什么这是?
前辈们请指教。小弟感激不尽。
例如下面的代码
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......
.......
只执行了第一句
第二句就没执行。为什么?
为什么这是?
前辈们请指教。小弟感激不尽。
解决方案 »
- myeclipse自动排序时怎么让被注释的也排序?
- [原创]Java泛型的性能问题
- 如何将字符串"1,2,3"转换成int[](把逗号去掉)
- 运行applet之后,ie中显示 "No Java 2 support for APPLET!! " 请问该怎么解决啊?
- 小问题,up有分
- help!
- 【java -version】如果JDK安装正确
- 在JB7下能编译的文件,用JDK1.4.1为什么编译会出错了呢?
- java读取oracle的blob字段空指针错误!!!太奇怪了
- 我是菜菜鸟 很简单的问题啊 一定给分
- 奇怪的问题:The method a() is undefined for the type print
- 如果类中直接带 static 与 构造方法有什么不同?
看后台log应该能看到错误吧
使用批处理吧。。
rs.next()
都不这么用的,去看看帮助吧。
int upd = toUpdate.executeUpdate(".....这样
executeUpdate用于update ,delete 更新语句,而executeQuery用于select 等查询语句.
很强
很强
执行第二条
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();