- 论坛徽章:
- 0
|
想通过tbl1的数据来更新tbl2的数据,但每次执行rs2.updateRow(); 时会将tbl2中的所有记录都更新一次,照理说每次应该只更新rs2中的记录。先谢了。
try
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
Statement stmt2=null;
ResultSet rs2=null;
String name=null;
String sql1,sql2;
conn=ConnectionPool.getConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
sql1="select * from tbl1";
rs=stmt.executeQuery(sql1);
while(rs.next())
{
name=rs.getString("id");
stmt2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
sql2="select * from tbl2 where name=\""+name+"\"";
rs2=stmt2.executeQuery(sql2);
if (rs2.next())
{
//更新Title
if(rs.getString("Title") !=null)
{
rs2.updateString("Title",rs.getString("Title"));
rs2.updateRow();
}
}
rs2.close();
stmt2.close();
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
[ 本帖最后由 wysunxiaohua 于 2008-9-19 13:56 编辑 ] |
|