Results 1 to 3 of 3

Thread: how can i populate a jtable with data from a MySQL table?

  1. #1
    Senior Member
    Join Date
    May 2005
    Posts
    434
    Thanks
    0
    Thanked
    0 times in 0 posts

    how can i populate a jtable with data from a MySQL table?

    hi i have made a jtable and i dont know how to populate it with data from a MySQL table.

    i have no problem making a connection to the database and executiung queries, the problem lies in how can i actualy insert the values from a resulset into a table?

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    You understand that actual JTable data is stored "in" the class "DefaultTableModel" yes, using methods in the "TableModel" interface to interact with that data? If you look at the API you can see that "DefaultTableModel" inherits from the abstract class "AbstractTableModel". Why not write your own tablemodel class ("JonneysTableModel") that extends AbstractTableModel to retrieve the values via SQL from your database, and then call the JTable constructor "JTable(JonneysTableModel myModel)", specifying your own TableModel. That's probably the most noddy way to do it.

    If you're still stuck for what to do, why not look at the code for "DefaultTableModel" and see how Sun do it. (hint: Vector of Vectors for rows/columns). There is also a JTable constructor for vectors of data representing rows/columns.

    All of this is from just looking at the javadoc API, everything you need really is there. If you're still stuck, give me a PM and i'll offer what assitence I can time-permitting.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Also, as you're already familiar with the ResultSet Interface, have a look at the Interface ResultSetMetaData. With this you can try out some additional things by the looks of it, such as naming the columns in your JTable directly from your database table field names.
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Access 2002 Copy Data from Form into Table
    By hegaroo in forum Software
    Replies: 1
    Last Post: 09-03-2006, 03:06 PM
  2. Data Recovery
    By LayZeh in forum PC Hardware and Components
    Replies: 8
    Last Post: 04-08-2005, 11:00 PM
  3. Replies: 8
    Last Post: 21-05-2004, 09:58 PM

Posting Permissions

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