import java.awt.*; import java.sql.*; import java.io.*; public class Rapporto1 { static BufferedWriter myOutput; static String nomecomp[]=new String[20]; static int nhit[] = new int[20]; static int numc = 0; public static void main(String[] args) throws IOException{ String titolo = " "; String commento = " "; String testo = " "; String nomec = " "; int id=0; int nd =0; int nl = Integer.parseInt(args[0]); int nr =0; int nt =0; int nrt =0; int rc =0; int rd =0; int numcomp =0; try { // Load the Mysql JDBC driver try { Class.forName("org.gjt.mm.mysql.Driver"); } catch (ClassNotFoundException e) { System.out.println ("Mysql device driver does not exist"); System.exit(1); } // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost/Istogrammi?user=&password="); // Create a Statement Statement stmt = conn.createStatement (); File outputFile = new File("Rapporto1.html"); myOutput = new BufferedWriter(new FileWriter(outputFile)); ResultSet rset6 = stmt.executeQuery (" select Indirizzo FROM computer"); while (rset6.next()){ numcomp=numcomp+1; nomecomp[numcomp] = rset6.getString(1); nhit[numcomp] = 0; } ResultSet rset2 = stmt.executeQuery (" select COUNT(*) FROM test WHERE Num_lez="+nl ); myOutput.write( " \n"); nt = rset2.getInt(1); myOutput.write("Risultato test della lezione "+nl+"

Risultati test lezione "+nl+"

    \n"); for(int k=1;k<(numcomp+1);k++){ myOutput.write( "
"); else{ ResultSet rset3 = stmt.executeQuery (" select Risposta FROM istogrammi WHERE num_lez="+nl+" AND Num_test="+i+" AND Nome_computer='"+nomecomp[k]+"'" ); rd =rset3.getInt (1); if(rd==rc)nhit[k]=nhit[k]+1; if(nr == 1 && rd==rc) myOutput.write( ""); if(nr > 1 && rd==rc) myOutput.write( ""); if(rd!=rc) myOutput.write( ""); } } myOutput.write( "\n"); } myOutput.write( "
"+ k); for(int i=1;i<(nt+1);i++){ ResultSet rset = stmt.executeQuery (" select Risposta_corretta,ID FROM test WHERE Num_lez="+nl+" AND Num_test="+i ); rc = rset.getInt(1); id = rset.getInt(2); ResultSet rset1 = stmt.executeQuery (" select COUNT(*) FROM istogrammi WHERE Num_lez="+nl+" AND Num_test="+i+" AND Nome_computer='"+nomecomp[k]+"'" ); nr = rset1.getInt(1); if(nr == 0 ) myOutput.write( "    "+nhit[k]+"


\n"); myOutput.write( "
Pagina curata da Giuseppe Zito: zito@ba.infn.it
ultimo aggiornamento: \n"); myOutput.write( " \n"); myOutput.close(); stmt.close(); // Close the connection conn.close(); } catch (SQLException e) { System.out.println("Error accessing DB "); System.out.println(" Error code is : "+e.getErrorCode()); System.out.println(" Error message is :"+e.getMessage()); } } }