This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes checking for the existence of a column by name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "checking for the existence of a column by name" Watch "checking for the existence of a column by name" New topic
Author

checking for the existence of a column by name

Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
Like the title says, how in SQL, can I see if a column exists?
If I know 'tableA' exists, I can do:
SHOW COLUMNS FROM 'tableA' - but how can I see if there is a column named 'columnA' ? The following does not work:
SELECT COUNT(Field) FROM 'tableA' WHERE Field = 'columnA' IN (SHOW COLUMNS FROM `tableA`);
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

Hi Phil,
Since you asked in the JDBC forum (and I'm assuming you _only_ asked in the JDBC forum), I assume that you want to use JDBC in order to obtain the column details for a given database table.
In my opinion, you should use the "java.sql.DatabaseMetaData" interface, or the "java.sql.ResultSetMetaData" interface:
http://java.sun.com/j2se/1.4.1/docs/api/java/sql/DatabaseMetaData.html
http://java.sun.com/j2se/1.4.1/docs/api/java/sql/ResultSetMetaData.html
Hope this helps you.
Good Luck,
Avi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checking for the existence of a column by name