Re: Detecting if a table in a database already exists ?

From: Real Gagnon (realgagnon__at__yahooSpamIsBadSstripunderscore.com)
Date: 10/13/04


Date: Tue, 12 Oct 2004 22:02:09 GMT


> How do I find out from a java source if a table in a database already
> exists?

// ref : http://www.rgagnon.com/javadetails/java-0485.html

Connection c = ...
DatabaseMetaData dbm = c.getMetaData();
// check if "employee" table is there
ResultSet tables = dbm.getTables(null, null, "employee", null);
if (rs.next()) {
  // Table exists
}
else {
  // Table does not exist
}

Bye.

-- 
Real Gagnon  from  Quebec, Canada
* Looking for Java or PB snippets ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html