Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Populating a 2D Array from a resultSet

849310Mar 22 2011 — edited Mar 22 2011
Hi to all, my first post here and hopefully someone can help me with, what I hope, is a small issue.

I am trying to present the results of a select statement in a Jtable but I am only getting the final row of the set appear in the Jtable. The code I have written so far:
            String[] columnnames = {
               "Category ID",
               "Name",
               "Category Type"
           };

            while (result.next()) {
                int id = result.getInt("categoryid");
                String name = result.getString("name");
                String type = result.getString("categorytype");
                

                 Object data [][] =  {
                     {new Integer(id),
                     name,
                     type
                     }
                };
                

            JFrame frame = new JFrame("Table Printing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final JTable table = new JTable(data, columnnames);
            JScrollPane scrollPane = new JScrollPane(table);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);
            }
Regards

Tom

Edited by: 846307 on 22-Mar-2011 04:33
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2011
Added on Mar 22 2011
25 comments
2,389 views