コード例 #1
0
ファイル: ShowDaoImpl.java プロジェクト: aherain/translation
 // 查询一个学生的所有信息
 public Student selectSt(String username) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   Student student = null;
   String sql = "select * from student where username=? ";
   try {
     student = new Student();
     conn = JdbcUtil.getConnection();
     st = conn.prepareStatement(sql);
     st.setString(1, username);
     rs = st.executeQuery();
     while (rs.next()) {
       if (username.equals(rs.getString("username"))) {
         student.setId(rs.getInt("id"));
         student.setUsername(rs.getString("username"));
         student.setEmail(rs.getString("email"));
         student.setName(rs.getString("name"));
         student.setPhoto(rs.getString("photo"));
         student.setAnswer(rs.getString("answer"));
         student.setProtection(rs.getString("protection"));
         student.setTel(rs.getString("tel"));
         student.setView_photo(rs.getString("view_photo"));
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     JdbcUtil.release(conn, st, rs);
   }
   return student;
 }
コード例 #2
0
ファイル: ShowDaoImpl.java プロジェクト: aherain/translation
  // 查询所有学生信息 ,以注册时间为顺序
  public List<Student> selectAllSt(Page page) {
    Connection conn = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    List<Student> list = null;
    String sql = "select * from student order by register_date desc limit ?,?";
    try {
      conn = JdbcUtil.getConnection();
      list = new ArrayList<Student>();
      st = conn.prepareStatement(sql); // 预编译SQL语句
      st.setInt(1, page.getStart());
      st.setInt(2, page.getShowCount());
      rs = st.executeQuery();

      while (rs.next()) { // 逐行查询
        Student student = new Student();
        student.setId(rs.getInt("id"));
        student.setUsername(rs.getString("username"));
        student.setSex(rs.getString("sex"));
        student.setEmail(rs.getString("email"));
        student.setTel(rs.getString("tel"));
        student.setName(rs.getString("name"));
        student.setRegister_date(rs.getDate("register_date"));
        list.add(student);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      JdbcUtil.release(conn, st, rs);
    }
    return list;
  }
コード例 #3
0
ファイル: ShowDaoImpl.java プロジェクト: aherain/translation
  // 更新一个学生的所有信息
  public boolean updateSt(Student student) {
    Connection conn = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    String sql = "update student set name=?,tel=?,email=? where id=?";
    try {
      conn = JdbcUtil.getConnection();
      st = conn.prepareStatement(sql);
      st.setString(1, student.getName());
      st.setString(2, student.getTel());
      st.setString(3, student.getEmail());
      st.setInt(4, student.getId());
      st.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
      return false;
    } finally {
      JdbcUtil.release(conn, st, rs);
    }
    return true;
  }