1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| public void lister() {
AbonnerBD abonneBD=new AbonnerBD();
Vector ligne; Vector<String> colonne;
DefaultTableModel modele=null;
ligne = new Vector();
ResultSet resultat=abonneBD.liste();
ResultSetMetaData resulsetmd=null;
try
{
resulsetmd=resultat.getMetaData();
}
catch (SQLException ex) {
System.out.println(ex.getMessage());
}
colonne=new Vector<String>();
try
{
for(int i=0;i<resulsetmd.getColumnCount();i++)
colonne.addElement(resulsetmd.getColumnLabel(i+1));
}
catch (SQLException ex) {
System.out.println(ex.getMessage());
}
try {
while(resultat.next()){
Vector<String> cells=new Vector<String>();
for (int j = 1; j<=resulsetmd.getColumnCount(); j++) {
cells.addElement(resultat.getString(j));
}
ligne.addElement(cells);
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
modele=new DefaultTableModel(ligne,colonne);
Table_Abonne forme=new Table_Abonne();
forme.table.setModel(modele);
if (forme.table.getRowCount() > 0)
forme.table.setRowSelectionInterval(0, 0);
try {
resultat.close();
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
} |
Partager