@Override public void addStudent(Student student) { try { String query = "insert into UserDB.student (firstName, lastName, course, year) values (?,?,?,?)"; PreparedStatement preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, student.getFirstName()); preparedStatement.setString(2, student.getLastName()); preparedStatement.setString(3, student.getCourse()); preparedStatement.setInt(4, student.getYear()); preparedStatement.executeUpdate(); preparedStatement.close(); } catch (SQLException e) { e.printStackTrace(); } }
@Override public void updateStudent(Student student) { try { String query = "update UserDB.student set firstName=?, lastName=?, course=?, year=? where studentId=?"; PreparedStatement preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, student.getFirstName()); preparedStatement.setString(2, student.getLastName()); preparedStatement.setString(3, student.getCourse()); preparedStatement.setInt(4, student.getYear()); preparedStatement.setInt(5, student.getStudentId()); preparedStatement.executeUpdate(); preparedStatement.close(); } catch (SQLException e) { e.printStackTrace(); } }