The code snippet below transfer the contents of ResultSet to JTable.

Java Code:
// TableModel definition
String[] tableColumnsName = {"col 1","col 2","col 3"}; 
DefaultTableModel aModel = (DefaultTableModel) aTable.getModel();
aModel.setColumnIdentifiers(tableColumnsName);

// the query
ResultSet rs = 
   statement.executeQuery("select col1,col2,col3 from mytable");

// Loop through the ResultSet and transfer in the Model
java.sql.ResultSetMetaData rsmd = rs.getMetaData();
int colNo = rsmd.getColumnCount();
while(rs.next()){
 Object[] objects = new Object[colNo];
 // tanks to umit ozkan for the bug fix!
 for(int i=0;i<colNo;i++){
  objects[i]=rs.getObject(i+1);
  }
 aModel.addRow(objects);
}
aTable.setModel(aModel);