import java.awt.*; import java.sql.*; import java.io.*; public class Genera { static BufferedWriter myOutput; public static void main(String[] args) throws IOException{ String titolo = " "; String commento = " "; int id=0; int nd =0; int nr =0; int nl = Integer.parseInt(args[0]); int nt = Integer.parseInt(args[1]); 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("test1.php3"); myOutput = new BufferedWriter(new FileWriter(outputFile)); ResultSet rset = stmt.executeQuery (" select Titolo,Commento,Num_domande,Risposta_corretta,ID FROM test WHERE Num_lez="+nl+" AND Num_test="+nt ); titolo =rset.getString (1); commento=rset.getString (2); nd = rset.getInt(3); rc = rset.getInt(4); id = rset.getInt(5); String testo[]= new String[nd]; for(int j= 1; j<(nd+1);j++){ ResultSet rset1 = stmt.executeQuery (" select Testo FROM domande WHERE id_test="+id+" AND num_test="+j ); testo[j-1] =rset1.getString (1); } myOutput.write("Quiz $num_test della lezione $num_lez : $titolo
$commento\";\n ?>"); myOutput.write( "
\n \\n\";\n echo \"\\n\";"); myOutput.write( "for ($i=1;$i<($num_domande+1);$i++) {\n $result = mysql_query(\"Select ID from istogrammi WHERE Risposta=$i AND\n Num_test=$num_test AND Num_lez=$num_lez\");\n $r[i] = mysql_numrows($result);\n echo \"\\n\";\n $total=$total+$r[i];\n }\n echo \"\\n\";\n echo \"
DomandaNum. risposte
$i$r[i]
TOTALE$total
   \\n\";\n "); myOutput.write( "echo \"\\n\";for ($i=1;$i<($num_computer+1);$i++) {\n $result = mysql_query(\"Select Nome,Indirizzo from computer WHERE ID=$i\");\n $nomec = mysql_result($result,0,\"Nome\");\n $indc = mysql_result($result,0,\"Indirizzo\");\n $result = mysql_query(\"Select ID from istogrammi WHERE Nome_computer='$indc' AND Num_test=$num_test AND Num_lez=$num_lez\");\n $r[$i] = mysql_numrows($result);\n $nome[$i] = $nomec;\n } echo \"\\n\"; for ($i=1;$i<($num_computer+1-7);$i++) { $i1 = 15 - $i; echo \"\\n\"; } echo \"
ComputerNum. risposteComputerNum. risposte
$nome[15]$r[15]
$nome[$i1]$r[$i1]$nome[$i]$r[$i]
\\n\"; }\n ?>\n
"); myOutput.write( "
\n
\" method=\"POST\">\n $i $domanda[$i]\\n\";\n }\n ?>\n

\n \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()); } } }