import java.awt.*; import java.sql.*; import java.io.*; public class Rapporto { 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; 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("Rapporto.html"); myOutput = new BufferedWriter(new FileWriter(outputFile)); ResultSet rset2 = stmt.executeQuery (" select COUNT(*) FROM test WHERE Num_lez="+nl ); nt = rset2.getInt(1); myOutput.write("Risultato test della lezione "+nl+"

Risultati test lezione "+nl+"

    \n"); for(int i=1;i<(nt+1);i++){ ResultSet rset = stmt.executeQuery (" select Titolo,Commento,Num_domande,Risposta_corretta,ID FROM test WHERE Num_lez="+nl+" AND Num_test="+i ); titolo =rset.getString (1); commento=rset.getString (2); nd = rset.getInt(3); rc = rset.getInt(4); id = rset.getInt(5); myOutput.write( "
  1. "+ titolo+"("+rc+") \n
    "+commento+"\n"); myOutput.write( " \n"); nrt = 0; for(int j= 1; j<(nd+1);j++){ ResultSet rset1 = stmt.executeQuery (" select COUNT(*) FROM istogrammi WHERE Num_lez="+nl+" AND Num_test="+i+" AND Risposta="+j ); nr = rset1.getInt(1); azzera(); ResultSet rset4 = stmt.executeQuery (" select Nome_computer FROM istogrammi WHERE Num_lez="+nl+" AND Num_test="+i+" AND Risposta="+j ); while (rset4.next ()) { nomec =rset4.getString (1); memorizza(nomec); } nr = conta(); ResultSet rset3 = stmt.executeQuery (" select Testo FROM domande WHERE id_test="+id+" AND Num_test="+j ); testo =rset3.getString (1); myOutput.write( "
    "+j+""+nr+""+testo+" \n"); nrt=nrt+nr; mostra(); } myOutput.write( "


    \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()); } } public static void azzera(){ numc = 0; for(int i=0;i "+(i+1)+" "+nhit[i]+" "+nomecomp[i]+" \n"); } } }