JDBC实战-搭建模型层IV这一节,以下代码可以实现,但是换成了public List<Goddess> query(String name) throws Exception后却发现result.size()的大小为0,这是因为什么,是不是因为result.add(g),没有将数据添加进去,具体代码已经被心态爆炸的我删掉了,求各位帮助下
public List<Goddess> query() throws Exception{
List<Goddess> result=new ArrayList<Goddess>();
Connection conn=DBUtil.getConnection();
StringBuilder sb=new StringBuilder();
sb.append("select id,user_name,age from imooc_goddess ");
PreparedStatement ptmt=conn.prepareStatement(sb.toString());
ResultSet rs=ptmt.executeQuery();
Goddess g=null;
while(rs.next()){
g=new Goddess();
g.setId(rs.getInt("id"));
g.setUser_name(rs.getString("user_name"));
g.setAge(rs.getInt("age"));
result.add(g);
}
return result;
}