• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing JTable and JDBC  RSS feed

 
Pradyumna Sahoo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want my JTable to retrieve data form database and show it in a grid view , Thanks for your time and consideration.
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 135
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following example retrives data from table named "Customer"(without quotes) in database named "MYDATABASE" (without quotes) where "name","address" are the fields of the table.
Customer is a model class. (hope you know how to pass arguments with constructor)
This method returns an ArrayList of Customer.



Note : use DefaultTableModel instead for TableModel (trust me it's worthy).
when you want to add data simply insert them in to a Object[].
in instance of DefaultTableModel contains method named addRow(); and pass that Object[].
it will insert data in Object[] to the JTable.

Hope this was helpful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!