首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > IBM DB2 >

紧急ResultSet嵌套有关问题

2012-02-22 
紧急求救ResultSet嵌套问题突然发现我的db2中的表如果是出于查询状态,那么再update就过不去了,在调试状态

紧急求救ResultSet嵌套问题
突然发现我的db2中的表如果是出于查询状态,那么再update就过不去了,在调试状态就停在update语句上不动了。而且表锁了。开发工具是WebSphere   。那位大侠知道是什么原因?

Connection   cn=null;
InitialContext   ctx=null;
DataSource   ds=null;
Statement   stmt=null;
ResultSet   rs=null;

Statement   tempstmt=null;
ResultSet   temprs=null;

ctx   =   new   InitialContext();
ds=(DataSource)   ctx.lookup( "wmsmngjndi ");
cn=ds.getConnection();
stmt=cn.createStatement();  
tempstmt=cn.createStatement();  

String   tmpstr= " ";

rs=stmt.executeQuery( "select   *   from   table1 ");  

while(rs.next()){
        tmpstr=rs.getString( "r1 ");
        tempstmt.executeUpdate( "update   table1   set   stat= 'Y '   where   r1= ' "+tmpstr+ " ' ");

}

在调试状态下当运行到tempstmt.executeUpdate( "update   table1   set   stat= 'Y '   where   r1= ' "+tmpstr+ " ' ");就不动了。


[解决办法]
将这几行代码
/////////////////
rs=stmt.executeQuery( "select * from table1 ");

while(rs.next()){
tmpstr=rs.getString( "r1 ");
tempstmt.executeUpdate( "update table1 set stat= 'Y ' where r1= ' "+tmpstr+ " ' ");

}
/////////////////
改为
////////////
tempstmt.executeUpdate( "update table1 set stat= 'Y ' where r1= ' "+tmpstr+ " ' ");
///////////
功能是一样的,前面的代码,你是想把table1的stat变成 'Y ',这一条语句就能做到,你再看看是不是?

热点排行