dao中方法get() ,获得一个对象时为何还要while(rs.next)?
public goddess get(Integer id) throws Exception{
Connection conn=DBUtil.getConnection();
String sql=""+
" select * from goddess "+
" where id =? ";
PreparedStatement ptmt=conn.prepareStatement(sql);
ptmt.setInt(1, id);
ResultSet rs=ptmt.executeQuery();//executeQuery()用来执行查询
goddess g;
g=new goddess();
while(rs.next()){
g.setUser_name(rs.getString("user_name"));
g.setAge(rs.getInt("age"));
g.setEmail(rs.getString("email"));
}
return g ;
}
既然数据库查询返回已经是一个条目了,为什么还要循环赋值?
难道rs.next() 不是读取下一个条目?