// Cognome e Nome: Cognome, Nome // Numero di matricola: // Data di Nascita: // login su SQL server: // Password su SQL server: import java.sql.*; import java.io.*; class punto3_4 { // subname deve essere sostituito con l'identificatore ODBC creato static String Con_URL = "jdbc:odbc:subname"; public static void main (String args []) //args[0]=Barca { try{ Connection con; // caricamento driver Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); // connessione: N deve essere sostituito con il numero del vostro gruppo con =DriverManager.getConnection(Con_URL,"login","password"); // inserire chiamate per creare lo statement Statement st = con.createStatement(); String query = "select data, count(DISTINCT ruolo)"+ "from Noleggi" + "where barca='"+ args[0]+ "'"+ "group by data"; ResultSet rs = st.executeQuery(query); // stampa del risultato while (rs.next()) { if (rs.getInt(2)>2) System.out.println("Data: " + rs.getDate(1) + " la barca aveva a bordo un team di velisti che ricoprivano " + rs.getInt(2) + " ruoli distinti"); else System.out.println("In data: " + rs.getDate(1) + " la barca " + args[0] + " non ha equipaggio sufficiente"); } st.executeUpdate("delete from Barche"+ "where categoria = (select categoria from barche where targa='"+args[0]+"')"+ " and targa NOT IN (select barca from noleggi)"); st.executeUpdate("update Velisti set Bonus = Bonus * .90 where codice NOT IN (select velisti from Noleggi)"); // chiusura connessione con.close(); } catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } catch (SQLException e) { while( e!=null){ System.out.println("SQLState: " + e.getSQLState()); System.out.println(" Code: " + e.getErrorCode()); System.out.println(" Message: " + e.getMessage()); e = e.getNextException(); } } } }