Results 1 to 3 of 3
  1. #1
    happiocholloh is offline Member
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Database and JTable?!?

    Hi,
    Im trying to work my way through displaying database data.
    All the tutorials are old, not allowed vektors etc that they show.
    Ive got my database connected, Ive created a JTable and now Im just trying to combine them.

    Im thinking the easiest way is to do a while loop and push the results into an array and then add the object array into the model.

    Is there a best practice way or an up to date tutorial?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default Re: Database and JTable?!?

    Try Camickr's site; that man is a Swing wizard and knows about other aspects of Java too. There's something useful in his Swing section on that site.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Database and JTable?!?

    Quote Originally Posted by happiocholloh View Post
    Hi,
    Im trying to work my way through displaying database data.
    All the tutorials are old, not allowed vektors etc that they show.
    Ive got my database connected, Ive created a JTable and now Im just trying to combine them.

    Im thinking the easiest way is to do a while loop and push the results into an array and then add the object array into the model.

    Is there a best practice way or an up to date tutorial?
    Create a class that implements TableModel (for instance, extend DefaultTableModel) and implement - or override if you use inheritance - the appropriate methods (getRowCount/getColumnCount/getValueAt/etc...), then set the JTable TableModel to an instance of this class. This gives you a great amount of flexibility in how you can arrange your data in the backend.
    See How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

Similar Threads

  1. Creating a Database using JTable
    By joshuakeithlewis in forum New To Java
    Replies: 1
    Last Post: 12-23-2011, 09:00 AM
  2. Populating Jtable from database - better way?
    By madhura2212 in forum AWT / Swing
    Replies: 5
    Last Post: 10-05-2010, 02:04 PM
  3. Save JTable to database
    By Geraldo in forum AWT / Swing
    Replies: 0
    Last Post: 06-04-2010, 02:03 PM
  4. JTable and database
    By hendrix79 in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 10:15 PM
  5. import database in Jtable?
    By makpandian in forum AWT / Swing
    Replies: 3
    Last Post: 03-04-2009, 07:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •