public Reader read(String n) { Connection cn = null; PreparedStatement ps = null; ResultSet rs = null; Reader rd = null; try { cn = JDBCTools.getConnection(); String spl = "select r_name,r_age,r_typed,r_sex,r_dept,r_phone,r_address,r_photo from reader where r_id=?"; ps = cn.prepareStatement(spl); ps.setString(1, n); rs = ps.executeQuery(); while (rs.next()) { rd = new Reader(); rd.setName(rs.getString(1)); rd.setAge(rs.getInt(2)); rd.setTyped(rs.getInt(3)); rd.setSex(rs.getString(4)); rd.setDept(rs.getString(5)); rd.setPhone(rs.getString(6)); rd.setAddress(rs.getString(7)); rd.setPhoto(rs.getString(8)); } } catch (SQLException e) { throw new DaoException(e.getMessage(), e); } try { rs.close(); } catch (SQLException e) { throw new DaoException(); } finally { JDBCTools.free(ps, cn); } return rd; }