// Key part
Vector <string> columnnames = new vector <string> ();
Vector rows = new vector ();
// Execute the query and obtain the query result
Try {
String SQL = "select * From fnsubject ";
Con = dbconnection. getcon ();
Stmt = con. createstatement ();
Rs = stmt.exe cutequery (SQL );
Resultsetmetadata rsmd = Rs. getmetadata ();
Int colnum = rsmd. getcolumncount (); // obtain the number of Columns
Columnnames. Clear (); // clear all elements in the Set
For (INT column = 0; column <colnum; column ++ ){
Columnnames. addelement (rsmd. getcolumnlabel (column + 1 ));
}
// Obtain the information of all rows and add them to the vector rows.
Rows. Clear (); // clear the set
While (Rs. Next ()){
Vector <Object> newrow = new vector <Object> ();
For (INT I = 1; I <= colnum; I ++ ){
Newrow. addelement (Rs. GetObject (I ));
}
Rows. addelement (newrow );
}
} Catch (exception ex ){
}
// Create a table using the query results and display the table
Jdialog jd1 = new jdialog (this ,"");
Jtable book_table = new jtable (rows, columnnames );
Jscrollpane scrollpane1 = new jscrollpane (book_table );
Book_table.setpreferredscrollableviewportsize (new dimension (500, 70 ));
Jd1.getcontentpane (). Add (scrollpane1, borderlayout. center );
Jd1.setsize (450,150 );
Jd1.setlocation (550,100 );
Jd1.show ();