Solved

Dynamically creating jtables

Posted on 2004-04-28
3
218 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 50 total points
ID: 10936901
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

729 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