@Override public int doUpdate(int id, Student student) throws Exception { String sql = "update student set stuNumber=?,stuPassword=?,stuName=?,stuSex=?,stuIdentification=?,stuIsGat=?,stuPhone=?,departmentId=?,majorId=?,gradeNow=?,nationMark=?,birthday=?,address=?,politics=? where id=?"; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, student.getStuNumber()); pstmt.setString(2, student.getStuPassword()); pstmt.setString(3, student.getStuName()); pstmt.setString(4, student.getStuSex()); pstmt.setString(5, student.getStuIdentification()); pstmt.setString(6, student.getStuIsGat()); pstmt.setString(7, student.getStuPhone()); pstmt.setInt(8, student.getDepartmentId()); pstmt.setInt(9, student.getMajorId()); pstmt.setString(10, student.getGradeNow()); pstmt.setInt(11, student.getNationMark()); pstmt.setString(12, student.getBithday()); pstmt.setString(13, student.getAddress()); pstmt.setString(14, student.getPolitics()); pstmt.setInt(15, id); result = pstmt.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { DatabaseConnection.closePreparedStatement(pstmt); DatabaseConnection.closeConnection(conn); } return result; }
@Override public int doCreate(Student student) throws Exception { String sql = "insert into student(stuNumber,stuPassword,stuName,stuSex,stuIdentification,stuIsGat,stuPhone,departmentId,majorId,gradeNow,nationMark,birthday,address,politics) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try { pstmt = conn.prepareStatement(sql); pstmt.setString(1, student.getStuNumber()); pstmt.setString(2, student.getStuPassword()); pstmt.setString(3, student.getStuName()); pstmt.setString(4, student.getStuSex()); pstmt.setString(5, student.getStuIdentification()); pstmt.setString(6, student.getStuIsGat()); pstmt.setString(7, student.getStuPhone()); pstmt.setInt(8, student.getDepartmentId()); pstmt.setInt(9, student.getMajorId()); pstmt.setString(10, student.getGradeNow()); pstmt.setInt(11, student.getNationMark()); pstmt.setString(12, student.getBithday()); pstmt.setString(13, student.getAddress()); pstmt.setString(14, student.getPolitics()); result = pstmt.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { DatabaseConnection.closePreparedStatement(pstmt); DatabaseConnection.closeConnection(conn); } return result; }