Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to test if table exists

 
David Gilmore
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a database tools application and a portion of my code depends on whether or not a table exists in the database. Is there any way i can test for this? I have not been able to find any methods in the API.
 
Tanel Alumae
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
There are numerous methods in the DatabaseMetaData inteface for querying for existing tables, schemas, stored procedures, etc.
If the jdbc driver of your database doesn't support it, you can use a direct SQL query on the database metadata (e.g. "select table_name from user_tables" in Oracle) but then you lose portability.
Hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic