get the columnname of a given table in java

T

tolu45

Hi all,

I am new to java and i am writing a program to obtain the column names
of a given table. When i run the program, i get all the table name into
a jList using DatabaseMetaData. What i want now is iwhen i click on a
tablename in the jList, i will like to obtain the columnNames of this
JList element(table) in another JList2.

Regards,
 
M

Matt Humphrey

tolu45 said:
Hi all,

I am new to java and i am writing a program to obtain the column names
of a given table. When i run the program, i get all the table name into
a jList using DatabaseMetaData. What i want now is iwhen i click on a
tablename in the jList, i will like to obtain the columnNames of this
JList element(table) in another JList2.

You have to do a query to get some kind of data back and the result set will
have the column names in the data. (E.g. select * from tablename)

ResultSetMetaData rsm = resultSet.getMetaData ();
for (int i = 1; i <= rsm.getColumnCount(); ++i) {
String columnName = rsm.getColumnName(i);
}

Check the API for additional methods.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
C

Chris Smith

tolu45 said:
I am new to java and i am writing a program to obtain the column names
of a given table. When i run the program, i get all the table name into
a jList using DatabaseMetaData. What i want now is iwhen i click on a
tablename in the jList, i will like to obtain the columnNames of this
JList element(table) in another JList2.

Since you've already got a DatabaseMetaData, look up the getColumns
method. It will give you all the information you want. Matt's
suggestion will also work, but you'll get less information about the
columns and it's potentially very expensive.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top