I have a table and on a opening of a frame the table receives its columns and their respective headers from a table in mysql database. How can i insert all the values from the sql database table into the swing table?? Here is my code...
DefaultTableModel dtm=(DefaultTableModel)jTable1.getModel();
String query1=null;
try {
query1="select * from "+Variables.table+";";
ResultSet rsft=st.executeQuery(query1);
Object o[]=new Object[x];
while(rsft.next()) {
for(int i=1;i<=x;i++){
o[i-1]=rsft.getString(i);
}
dtm.addRow(o);
}
} catch(Exception e) {
System.out.println(e.getMessage());
}
In above code x is an integer denoting the number of colums in sql table. And Variables.table is a static variable containing the table name. Thank You