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
| try{
String query="SELECT * FROM registre";
ResultSet Rs=con.connect(query);
ResultSetMetaData RsMeta = con.getMeta(Rs);
int ncol = 0;
int nlignes = 0;
ncol = RsMeta.getColumnCount();
Rs.last();
nlignes = Rs.getRow();
String[] v = new String[ncol];
Object[][] tab = new String[nlignes][ncol];
int i=0;
int k=0;
Rs.first();
for(i=0; i<=nlignes-1; i++){
for(k=1;k<=ncol-1;k++){
v[k] = RsMeta.getColumnName(k);
tab[i][k]=Rs.getString(k);
}
}
DefaultTableModel tabl = new DefaultTableModel(tab,v);
this.tableRqt = new JTable(tabl);
this.getContentPane().add(new JScrollPane(tableRqt), BorderLayout.CENTER);
}catch(Exception e){
e.printStackTrace();
} |
Partager