public static void main(String[] args) throws Exception {
GoddessDao g = new GoddessDao();
List<Goddess> gs = g.query();
for(Goddess goddess : gs){
System.out.println(goddess.getUser_name()+","+goddess.getAge());
}
}
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();
g.setAge(rs.getInt("age"));
g.setUser_name(rs.getString("user_name"));
gs.add(g);
}
return gs;
}