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
| DataClass dc=new DataClass();
dc.reqSelect("select * from chambre");
try {
ResultSetMetaData meta=dc.rs.getMetaData();
Object[] column = new Object[meta.getColumnCount()];
for(int i=1;i<=meta.getColumnCount();i++){
column[i-1]=meta.getColumnName(i);
}
dc.rs.last();
int rowCount = dc.rs.getRow();
Object[][] data = new Object[rowCount][meta.getColumnCount()];
dc.rs.beforeFirst();
int j = 1;
while(dc.rs.next()){
for(int i = 1 ; i <= meta.getColumnCount(); i++){
data[j-1][i-1] = dc.rs.getObject(i);
}
j++;
}
dc.rs.close();
dc.st.close();
contentPane.setLayout(new BorderLayout(0, 0));
JTable table = new JTable(data,column);
table.setBounds(0, 0, 434, 262);
JScrollPane scrollPane = new JScrollPane(table);
contentPane.add(scrollPane);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} |
Partager