• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Swing JTable and JDBC

 
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.
 
Ranch Hand
Posts: 143
Android Java Linux
  • 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!