ma scusate, ma una classe può avere più di un costruttore?
quindi nel mio caso, che devo fare..
se in GestioneCd ho questa situazione:
codice:
DistributoreDB mt= new DistributoreDB(//se proprio è necessario,qui cosa gli devo passare);
mt.trova();
e in DistributoreDB ho questa:
codice:
public DistributoreDB(String driver, String dbUrl) //il costruttore
throws SQLException,ClassNotFoundException {
Class.forName(driver);//carica il driver
c=DriverManager.getConnection(dbUrl);//carica il nome del database
}
public VociSupporti[] trova() {//voglio richiamare questo metodo
Statement s=null;
ResultSet rs=null;
try {
s=c.createStatement();
rs=s.executeQuery("SELECT TITOLO,AUTORE,DIMENSIONE FROM PRODOTTO WHERE SUPPORTO=' ' ORDER BY DIMENSIONE DESC");
Vector voci= new Vector();
VociSupporti vcd;
String titolo,autore;
int dimensione;
while (rs.next()) {
titolo=rs.getString("TITOLO");
autore=rs.getString("AUTORE");
dimensione=rs.getInt("DIMENSIONE");
vcd=new VociSupporti(titolo,autore,dimensione);
voci.addElement(vcd);
}
VociSupporti[] risultato=new VociSupporti[voci.size()];
for (int i=0; i<risultato.length; i++) {
risultato[i]=(VociSupporti) voci.get(i);
}
return risultato;
}
catch (SQLException e) {
visualizzaEccezioneSQL(e);
return new VociSupporti[0];
}
finally {
try {
if (rs!=null) {
rs.close();
rs=null;
}
if (s!=null) {
s.close();
s=null;
}
}
catch (SQLException e) {
visualizzaEccezioneSQL(e);
}
}
}