aspose file tools*
The moose likes JDBC and the fly likes table or view does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "table or view does not exist" Watch "table or view does not exist" New topic
Author

table or view does not exist

ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
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.


Discussion - the powerfull way to excellence!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: table or view does not exist