Пример #1
0
 // 根据username查询某个老师信息
 public Teacher selectTh(String username) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   Teacher teacher = null;
   String sql = "select * from teacher where username=? ";
   try {
     teacher = new Teacher();
     conn = JdbcUtil.getConnection();
     st = conn.prepareStatement(sql);
     st.setString(1, username);
     rs = st.executeQuery();
     while (rs.next()) {
       if (username.equals(rs.getString("username"))) {
         teacher.setId(rs.getInt("id"));
         teacher.setName(rs.getString("name"));
         teacher.setSex(rs.getString("sex"));
         teacher.setTel(rs.getString("tel"));
         teacher.setScore(rs.getInt("score"));
         teacher.setBank(rs.getString("bank"));
         teacher.setPhoto(rs.getString("photo"));
         teacher.setAnswer(rs.getString("answer"));
         teacher.setEmail(rs.getString("email"));
         teacher.setBanknum(rs.getString("banknum"));
         teacher.setLanguage(rs.getString("language"));
         teacher.setBirthday(rs.getDate("birthday"));
         teacher.setCollege(rs.getString("college"));
         teacher.setUsername(rs.getString("username"));
         teacher.setView_photo(rs.getString("view_photo"));
         teacher.setPrice(rs.getString("price"));
         teacher.setEducation(rs.getString("education"));
         teacher.setProtection(rs.getString("protection"));
         teacher.setIntroduction(rs.getString("introduction"));
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     JdbcUtil.release(conn, st, rs);
   }
   return teacher;
 }
Пример #2
0
  // 分页展示老师信息
  public List<Teacher> selectAllTh(Page page) {
    Connection conn = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    List<Teacher> list = null;
    String sql = "select * from teacher order by score desc limit ?,?";
    try {
      conn = JdbcUtil.getConnection();
      list = new ArrayList<Teacher>();
      st = conn.prepareStatement(sql); // 预编译SQL语句
      st.setInt(1, page.getStart());
      st.setInt(2, page.getShowCount());
      rs = st.executeQuery();

      while (rs.next()) { // 逐行查询
        Teacher teacher = new Teacher();
        teacher.setId(rs.getInt("id"));
        teacher.setName(rs.getString("name"));
        teacher.setPhoto(rs.getString("photo"));
        teacher.setCollege(rs.getString("college"));
        teacher.setUsername(rs.getString("username"));
        teacher.setSex(rs.getString("sex"));
        teacher.setLanguage(rs.getString("language"));
        teacher.setEducation(rs.getString("education"));
        teacher.setEmail(rs.getString("email"));
        teacher.setTel(rs.getString("tel"));
        teacher.setScore(rs.getInt("score"));
        teacher.setBank(rs.getString("bank"));
        teacher.setBanknum(rs.getString("banknum"));
        list.add(teacher);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JdbcUtil.release(conn, st, rs);
    }
    return list;
  }