• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Check existence of table

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to be able to test for the existence of a table in oracle using a java stored procedure. If it exists, I populate it, it doesn't, I create it and then populate.
Any suggestions would be appreciated.
Thanks,
Bill
 
author & internet detective
Posts: 42165
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
Most databases have a table that lists all the tables in the database. I think it is called ALL_TABLES in Oracle. You could query this table to check for the existence of a table. If the query returns zero rows, you create it as you described.
 
Bill Earnhardt
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne, thanks for the helpful information and found the table you were talking about. I'll give this a try and let you know the outcome.
Thank you!
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A generic way might be to use the
Connection.getMetaData(),which will return you a DatabaseMetaData object.
you can use the getTables() api in there to get the list of tables.
Why write some db specific code when you can solve the whole thing through
generic JDBC code???
Another question that I might think of here is which one would be more efficient.
Writing something like "select tname from tab" or using the DatabaseMetadata approach??
Thanks,
Chinmay
 
Jeanne Boyarsky
author & internet detective
Posts: 42165
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chinmay,
Bill mentioned he is using a stored procedure. So he is probably locked into Oracle anyway (stored procs tend to be db specific.) I think the SQL query would be more efficient because it only needs to return one item rather than the list of tables. This could make a difference if there are a lot of tables.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic