Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

get the columnname of a given table in java

Thread view: 
tolu45 - 27 Nov 2005 13:08 GMT
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,
Matt Humphrey - 27 Nov 2005 14:38 GMT
> Hi all,
>
[quoted text clipped - 3 lines]
> 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 matth@ivizNOSPAM.com  http://www.iviz.com/
Chris Smith - 27 Nov 2005 15:03 GMT
> 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.

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.