Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether table with given name exists in oracle through Java?

Tags:

java

I have csv file and i want to import that data to oracle database. but before that i want it to check whether table 'xyz' exist in database or not.

I want to do it through java .. anyone knows how to do it through java ?

like image 848
Sachin Doiphode Avatar asked Dec 14 '25 13:12

Sachin Doiphode


2 Answers

You can use the available meta data:

DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getTables(null, null, null, 
     new String[] {"TABLE"});
  while (res.next()) {
     System.out.println(
        "   "+res.getString("TABLE_CAT") 
       + ", "+res.getString("TABLE_SCHEM")
       + ", "+res.getString("TABLE_NAME")
       + ", "+res.getString("TABLE_TYPE")
       + ", "+res.getString("REMARKS")); 
  }

See here for more details.

like image 113
Umesh K Avatar answered Dec 17 '25 03:12

Umesh K


Wikipedia has some good info on getting at oracle metadata.

 SELECT
 COUNT(1)
 FROM
 ALL_TABLES
 WHERE
 TABLE_NAME = 'NAME_OF_TABLE'

Replace NAME_OF_TABLE with the name of your table and if you get a result of 1, you have your table.

like image 44
krock Avatar answered Dec 17 '25 03:12

krock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!