try{
DataRequest = Db.createStatement();
Results = DataRequest.executeQuery("SELECT * FROM Employee");
rm = Results.getMetaData();
col = rm.getColumnCount(); //getColumnCount and store it in integer variable col;
Vector colNames = new Vector();
for (int i = 1; i<= col; i++){
colNames.addElement(rm.getColumnName(i));
}
while(Results.next()){
Vector row = new Vector();
for(int i = 1; i <= col; i++){
row.addElement(Results.getObject(i));
}
data.addElement(row);
}
jDataTable.setModel(new DefaultTableModel(data,colNames));
jDataTable.revalidate();
Results.close();
}
catch (SQLException sql){
JOptionPane.showMessageDialog(this, "Cannot connect to Database"+sql,"Error", JOptionPane.WARNING_MESSAGE);
}
Partager