public void updateMusician(Musician m) { try { PreparedStatement stmt = conn.prepareStatement( "update musicians m set first_name = ?," + "last_name = ?, birthdate = ?, habitation_id = ?, password = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, m.getFirstName()); stmt.setString(2, m.getLastName()); stmt.setTimestamp(3, new java.sql.Timestamp(m.getBirthdate().getTime())); stmt.setInt(4, m.getHabitation().getId()); stmt.setString(5, m.getPassword()); stmt.executeUpdate(); // set instrument_skills stmt = conn.prepareStatement( "delete from instrument_skills where musician_id = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, m.getId()); stmt.executeUpdate(); for (Instrument i : m.getSkills()) { stmt = conn.prepareStatement( "insert into instrument_skills values(?, ?)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, m.getId()); stmt.setInt(2, i.getId()); stmt.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } }
public Band allAvailableTimes(Band band) { Band ret = band; band.getLeader().setAvailableTimes(new Vector<AvailableTime>()); for (Musician m : band.getMusicians()) { m.setAvailableTimes(new Vector<AvailableTime>()); } try { PreparedStatement stmt = conn.prepareStatement( "select id, musician_id, start_time, end_time from available_times where band_id = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setInt(1, band.getId()); ResultSet rs = stmt.executeQuery(); while (rs.next()) { for (Musician m : band.getMusicians()) { if (m.getId() == rs.getInt(2)) { m.addAvailableTime( new AvailableTime(rs.getInt(1), rs.getTimestamp(3), rs.getTimestamp(4))); } } if (band.getLeader().getId() == rs.getInt(2)) { band.getLeader() .addAvailableTime( new AvailableTime(rs.getInt(1), rs.getTimestamp(3), rs.getTimestamp(4))); } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; }