wood burning stoves 2.0*
The moose likes JDBC and the fly likes Detect if table exists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Detect if table exists" Watch "Detect if table exists" New topic
Author

Detect if table exists

Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

This should be easy, but I am unable to find it now.
How can I detect if a particular table exists or not in my DB (I am using
MySQL).

I cannot delete table, so I can't use drop if exists; but can I use count
(*) if exists, or sth similar? I am not much of a DB person.
Any pointers would be very useful.

TIA,
- Manish
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I think , you should be use some tool for manage MySQL DB such as MySQLFront, phpadmin ...


This for help.

MySQLFront
PHP myadmin


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

I didn't say I need to manage MySQL. I needed to detect in my code if te table existed. Anyway, I have found a way to do this with MetaData.

- Manish
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341

How can I detect if a particular table exists or not in my DB (I am using
MySQL).


mysql>show tables;


I cannot delete table, so I can't use drop if exists; but can I use count
(*) if exists, or sth similar?


Check your access privilege on the database.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

I cannot delete table, so I can't use drop if exists; but can I use count
(*) if exists, or sth similar? I am not much of a DB person.

If you want to see the data within a table, make sure that you have the *select* privilege.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the JDBC forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I think what Manish was after is something like:

Manish, if so could you post the name of the useful MySQL data dictionary (metadata) table(s)?

Thanks

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Detect if table exists
 
Similar Threads
saving multiple rows
InnerHTML and outerHTML not working in Netscape
Detect if a table exists
jdbc hsqldb issue - table not found
Detecting double clicks in a JTable