?
Solved

Dynamically creating jtables

Posted on 2004-04-28
3
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
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 150 total points
ID: 10936901
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 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