I want to determine if a column exists in a table for any jdbc driver.
In order to know the columns in a table, I have to make a query to the table and then get the ResultSetMetaData for the info, but this is pretty expensive in like 99% of times.
In mysql I have:
SELECT * FROM tablename LIMIT 0,0
In Intersystems caché I have:
SELECT TOP 0 * FROM tablename
But, for example, in JavaDB I cannot apply any limit at all.
Is there any generic query that would give me the same result and still be fair with the DB performance?
Thanks in advance.
SELECT * FROM tableName WHERE 'You' = 'Smart'
...or you could just use the DatabaseMetaData route.
There's a "getColumns" method that does what you need without creating a resultset.
SELECT * FROM table_name WHERE 1 = 2;
select * from tablename where 1 != 1
Unrelated, but if you just need the columns in MySQL, you can run SHOW FIELDS FROM tablename. This returns columns and the associated info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With