// 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]=Guida { 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 cognome,nome, count(*) " + "from Escursione, guide " + "where data between '1/1/2002' and '12/31/2002' and Escursione.guida=Guide.codice" + "group by guida, cognome, nome" + "having count(*) > (select count(*)" + "from Escursioni " + "where data between '1/1/2002' and '12/31/2002' and guida = '" + args[0] + "')"; ResultSet rs = st.executeQuery(query); // stampa del risultato while (rs.next()) { System.out.println("Nell'anno 2002 la guida: " + rs.getString(0) + " " + rs.getString(1) + " ha coordinato " + rs.getInt(2) + " escursioni"); } st.executeUpdate("update Guide set costoG = CostoG * .8 where codice NOT IN (select guida from Escursione where data between '1/1/2002' and '12/31/2002')"); st.executeUpdate("delete from Guide where eta >= 40 and costoG < 20"); // 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(); } } } }