读书人

紧急ResultSet嵌套有关问题

发布时间: 2012-02-22 19:36:56 作者: rapoo

紧急求救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 ',这一条语句就能做到,你再看看是不是?

读书人网 >IBM DB2

热点推荐