home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.disi.unige.it
/
2015-02-11.ftp.disi.unige.it.tar
/
ftp.disi.unige.it
/
pub
/
.person
/
MesitiM
/
teach
/
sol9JDBC1.java
< prev
next >
Wrap
Text File
|
2003-05-26
|
2KB
|
80 lines
// 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 grN1
{
// subname deve essere sostituito con l'identificatore ODBC creato
static String Con_URL = "jdbc:odbc:subname";
public static void main (String args [])
{
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();
// inserire chiamate per eseguire lo statement
String query = "select cognome, nome, avg(saldo) from persone, contoCorrente, Filiali where codiceFiscale = titolare and filiale = codice and citta = '" + args[0] + "' group by cognome, nome, filiale";
// query precedente indentata
// select cognome, nome, avg(saldo)
// from persone, contoCorrente, Filiali
// where codiceFiscale = titolare and filiale = codice and
// citta = 'parametro'
// group by cognome, nome, filiale
System.out.println(query);
ResultSet rs = st.executeQuery(query);
// analisi risultato con cursore
while (rs.next())
{
System.out.println("Cognome: " + rs.getString(1) + " Nome: " +
rs.getString(2) + " saldo medio: " + rs.getFloat(3));
}
// 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();
}
}
}
}