Solved

Dynamically creating jtables

Posted on 2004-04-28
3
189 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

759 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

24 Experts available now in Live!

Get 1:1 Help Now