public List<Goddess> query() throws Exception {
Connection conn = DBUtil.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt
.executeQuery("select user_name,age from imooc_goddess");
List<Goddess> gs = new ArrayList<Goddess>();
Goddess g = null;
while (rs.next()) {
g = new Goddess();
// String username=rs.getString("user_name");
// g.setUserName(username);
g.setUser_name(rs.getString("user_name"));
g.setAge(rs.getInt("age"));
gs.add(g);
}
return gs;
}
你看的这个是通过名字进行查询,你想通过ID进行查询只需将sb.append("where user_name = ?")改成sb.append("where id=?")就行了。