void queryTable (Connection conn)//, String espressione)
{
ResultSet rs;
ta.setText("");
ArrayList array = new ArrayList();
String[] cols=null;
try {
dbst = conn.createStatement();
rs=dbst.executeQuery("....."); //esegue query,lunga da scrive
if(rs!=null) {
/***********VISUALIZZAZIONE TABELLA******************/
while (rs.next()) {
String[] row = {rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7),
rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14)};
array.add(row);
}
ResultSetMetaData rsmd = rs.getMetaData();
cols = new String[rsmd.getColumnCount()];
for (int i=0; i<cols.length; i++) {
cols[i] = rsmd.getColumnName(i + 1);
}
} else { // La query non ha ritornato risultati
ta.append("Nessun record nella tabella\n");
}
rs.close();
dbst.close ();
conn.close ();
} catch (SQLException e) {
printException ("Non riesco a estrarre i dati dalla tabella",e);
return;
}
fintabella(array,cols);
flag3=false;
flag2=false;
}
/***************FINESTRA*************TABELLA******* **/
void fintabella (ArrayList array,String[] cols)
{
JFrame fintab = new JFrame("Archivio Completo");
fintab.setSize(600,500);
JPanel cptable= new JPanel();
cptable.setLayout(new BorderLayout());
cptable.setPreferredSize(new Dimension(600,500));
JTable table = new JTable((String[][])array.toArray(), cols);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COL UMNS);
cptable.add (table,BorderLayout.CENTER);
fintab.setContentPane(cptable);
fintab.pack();
fintab.show();
}
NON ho nessun errore di compilazione, ma la finestra non me la mostra, che posso fare?. Il problema è il try catch, xchè se creo una finestra fuori dal try catch tutto funziona, ma il problema è che non posso inserire la tabella se non ho ottenuto i valori dal resulset.
Grazie per ogni aiuto.