/** * Method that edits a class from a database * * @author Ognjen Mišiæ * @param ca Class attendance we want to edit * @param classID we identify the class attendance by class id parameter * @throws ParseException * @throws SQLException */ public static void editClass(ClassAttendance ca, int classID) throws ParseException, SQLException { try { conn = connectToDb(); stmnt = createReadOnlyStatement(conn); rs = stmnt.executeQuery(SELECT_ALL_FROM_CLASSES_ATTENDANCE); String sql = "UPDATE classes_attendance SET class_description='" + ca.getClassDescription() + "', date='" + ca.getDate() + "', duration='" + ca.getDuration() + "' WHERE class_id='" + classID + "';"; while (rs.next()) { if (rs.getInt("class_id") == ca.getClassID()) { Statement stmnt2 = createUpdateableStatement(conn); if (ca.getClassDescription().length() < 2) { setErrorMessage("Invalid class description"); break; } else if (!isValidDate(ca.getDate())) { setErrorMessage("Invalid date."); break; } else if (ca.getDuration() < 1) { setErrorMessage("Invalid class duration"); break; } else { setErrorMessage(null); stmnt2.executeUpdate(sql); break; } } } } catch (SQLException e) { e.printStackTrace(); } finally { if (rs != null) { rs.close(); } closeStatement(stmnt); closeConnection(conn); } }