Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checking for the existence of a column by name

 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic