// 分页查询所有状态 public List<Teacher> selectAllAds(Page page) { Connection conn = null; PreparedStatement st = null; ResultSet rs = null; List<Teacher> list = null; String sql = "select * from ads order by ads_date desc limit ?,?"; try { conn = JdbcUtil.getConnection(); list = new ArrayList<Teacher>(); st = conn.prepareStatement(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.setUsername(rs.getString("thusername")); teacher.setContent(rs.getString("content")); teacher.setAds_date(Date.valueOf(rs.getString("ads_date"))); list.add(teacher); } } catch (SQLException e) { e.printStackTrace(); } finally { JdbcUtil.release(conn, st, rs); } return list; }
// 根据username查询某个老师发布的信息 public List<Teacher> selectAds(Teacher teacher) { Connection conn = null; PreparedStatement st = null; ResultSet rs = null; List<Teacher> list = null; String sql = "select * from ads where thusername=? order by ads_date desc limit 0,4"; try { list = new ArrayList<Teacher>(); conn = JdbcUtil.getConnection(); st = conn.prepareStatement(sql); st.setString(1, teacher.getUsername()); rs = st.executeQuery(); while (rs.next()) { Teacher _teacher = new Teacher(); _teacher.setUsername(teacher.getUsername()); _teacher.setContent(rs.getString("content")); _teacher.setAds_date(rs.getDate("ads_date")); list.add(_teacher); } } catch (SQLException e) { e.printStackTrace(); } finally { JdbcUtil.release(conn, st, rs); } return list; }
// 根据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; }
// 分页展示老师信息 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; }