Solved

Dynamically creating jtables

Posted on 2004-04-28
3
203 Views
Last Modified: 2010-03-31
Hi,

I have a problem, hence me being here, I would like to create an application that can connect to a database, retrive the data and then display this data in a table.

I have two problems, the first is, how do I display this data in a table, and the 2nd is how do I change the amount of columns in the table to reflect the ammount of columns in the database table?

ANy assistance would be great.

Jon
0
Comment
Question by:levyuk
3 Comments
 
LVL 3

Expert Comment

by:fave_17
ID: 10936458
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 10936513
You must get ResultSet from database connection after executing Statement.execQuery, from that ResultSet You get all the data You need - column count & names, the databse data... Then you make a JTable just like that:
=============
import java.awt.*;
import javax.swing.*;

public class B extends JFrame {
  B() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = getContentPane();
    cp.add(new JTable(5,4));
    setSize(300,300);
    setVisible(true);
  }
  public static void main(String[] args)
  {
    B b = new B();
  }
}
===========
and depending on the data You manage to get from ResultSet and ResultSetMetaData fill in the table.

Good luck.
0
 
LVL 7

Accepted Solution

by:
maheshexp earned 50 total points
ID: 10936901
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now