Hi I want to fetch data from database and display into JTable. How can I achieve this?
Here is my table query for table:
select id,name,father from employee
Here is my code:
public static void main( String[] str ) {
String[] colName = new String[] { "Product Name" ,"Price" };
Object[][] products = new Object[][] {
{ "Galleta" ,"$80" },
{ "Malta" ,"$40" },
{ "Nestea" ,"$120" }
};
JTable table = new JTable( products, colName );
JFrame frame = new JFrame( "Simple Table Example" );
// create scroll pane for wrapping the table and add
// it to the frame
frame.add( new JScrollPane( table ) );
frame.pack();
frame.setVisible( true );
}
ResultSetTableModel(search on that term), or iterate the result set and put each entry into a custom table model of your own.