try
{
PreparedStatement psm=con.prepareStatement("select * from pubs where id=?");
psm.setString(1,jTextID.getText());
rs=psm.executeQuery();
rs.next();//为什么需要调用这个方法呢?
try
{
jTextID.setText(rs.getString(1));
jTextName.setText(rs.getString(2));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
{
PreparedStatement psm=con.prepareStatement("select * from pubs where id=?");
psm.setString(1,jTextID.getText());
rs=psm.executeQuery();
rs.next();//为什么需要调用这个方法呢?
try
{
jTextID.setText(rs.getString(1));
jTextName.setText(rs.getString(2));
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
Moves the cursor down one row from its current position.
游标初始位置是0
下移一个位置到第一条记录
jTextID.setText(rs.getString(1));
jTextName.setText(rs.getString(2));
就不能得到正确的结果至于为什么会把游标初始化为0 而不是指向第一条记录 考虑一下当返回结果集是一个空集的情况就会很容易明白了
一般 if(rs.next()) or while(rs.next())