Exemple #1
0
 // 分页查询所有状态
 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;
 }
Exemple #2
0
 // 根据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;
 }