public List<Category> getCategoryList() throws SQLException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = DbUtil.getConnection();
String sql = "select * from category";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery(sql);
List<Category> categoryList = new ArrayList<Category>();
Category c = new Category();
while (rs.next()) {
c.setcId(rs.getInt("cId"));
System.out.println("ci Dao===="+rs.getInt("cId"));
c.setName(rs.getString("name"));
c.setDescribes(rs.getString("describes"));
c.setContentTime(rs.getString("contentTime"));
categoryList.add(c);
}
System.out.println("categoryList.get(0).getCid()=="+categoryList.get(0).getcId());//输出3
System.out.println("categoryList.get(1).getCid()=="+categoryList.get(1).getcId());//输出3 和上面的一样 ???????
return categoryList;
} finally {
DbUtil.close(rs, ps);
}
}
慕婉清6462132
白板的微信
相关分类