import java.awt.*; import java.sql.*; import java.io.*; public class Gallerie { static BufferedWriter myOutput; public static void main(String[] args) throws IOException{ String nome = " "; String commento = " "; String indirizzo = " "; String miniatura = " "; int id=0,ida=0; String nomeautore=""; int i=0,ngall=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/Frattali?user=utente&password="); // Create a Statement Statement stmt = conn.createStatement (); File outputFile = new File("gallerie.html"); myOutput = new BufferedWriter(new FileWriter(outputFile)); ResultSet rset0 = stmt.executeQuery (" select COUNT(*) from gallerie" ); ngall=rset0.getInt(1); myOutput.write("

\n"); myOutput.write(" \n The database contains "+ngall+" galleries.A list ordered by author name is also available
\n");
ResultSet rset = stmt.executeQuery (" select Nome,Commento,Indirizzo,ID,autore,miniatura,nome_autore from gallerie,autore WHERE autore=ID_autore ORDER BY Nome" );
while (rset.next ()) {
i = i + 1;
nome =rset.getString (1);
commento=rset.getString (2);
indirizzo = rset.getString(3);
id = rset.getInt(4);
ida =rset.getInt (5);
miniatura = rset.getString(6);
nomeautore = rset.getString(7);
myOutput.write(
"
"+nome+"");
if(ida>0)myOutput.write(
" by "+nomeautore+"\n");
if(commento != null)myOutput.write(" : "+commento+" \n");
}
myOutput.write(
"