This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

table or view does not exist

 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey pals,

Please let me know,

How do i check from java that

if a table exists in oracle

it must not create a new one

else

create a new one.

when i gave

select count of *from tablename;

it said no of rows = some int.

i checked a table is there but when table is not there

it gave me an exception

"table or view does not exist"

should i write my code to create the table inside the exception block. ?

???

could some one tell me the best practice in this case !!!


thanks for your help in this.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All databases have a catalog you can query to find out meta data about the database itself. In Oracle you can check a table called user_tables for example. However, a better way to do this is to use the DatabaseMetaData class which gas a getTables() method you can use to find out what tables exist. Doing it this way means your code is not Oracle specific.
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
All databases have a catalog you can query to find out meta data about the database itself. In Oracle you can check a table called user_tables for example. However, a better way to do this is to use the DatabaseMetaData class which gas a getTables() method you can use to find out what tables exist. Doing it this way means your code is not Oracle specific.


Thanks for the idea.

Am trying to implement the same.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic