结果对,但是是红色的,是怎么一回事?
// 按条件来查找女神 public List<Goddess> query(String name) throws Exception{ Connection conn = DBUtil.getConnection(); List<Goddess> gList = new ArrayList<Goddess>(); Goddess g = null; // 一个可变的字符序列StringBuilder StringBuilder sql = new StringBuilder(); // 将指定的字符串追加到此字符序列。 sql.append("select * from imooc_goddess"); sql.append(" where user_name= ?"); PreparedStatement ptmt = conn.prepareStatement(sql.toString()); ptmt.setString(1,name); ResultSet resu = ptmt.executeQuery(); while(resu.next()){ g = new Goddess(); g.setId(resu.getInt("id")); g.setUser_name(resu.getString("user_name")); g.setSex(resu.getInt("sex")); g.setAge(resu.getInt("age")); g.setBirthday(resu.getDate("birthday")); g.setEmail(resu.getString("email")); g.setMobile(resu.getString("mobile")); g.setCreate_user(resu.getString("create_user")); g.setCreate_date(resu.getDate("create_date")); g.setUpdate_user(resu.getString("update_user")); g.setUpdate_date(resu.getDate("update_date")); g.setIsdel(resu.getInt("isdel")); gList.add(g); } return gList; }
测试:
GoddessDao gd = new GoddessDao(); List<Goddess> glist = gd.query("王尼玛"); for (int i = 0; i < glist.size(); i++) { System.err.println(glist.get(i).toString()); }