| 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: 1114
|
|
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.
|
 |
 |
|
|
subject: checking for the existence of a column by name
|
|
|