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

From: Robert Klemme (bob.news_at_gmx.net)
Date: 10/13/04


Date: Wed, 13 Oct 2004 15:00:04 +0200


"Thomas Kellerer" <OSCUQDVXTKFJ@spammotel.com> schrieb im Newsbeitrag
news:2t4gpnF1rj8ahU1@uni-berlin.de...
> On 13.10.2004 12:56 Robert Klemme wrote:
> >>DatabaseMetaData.getTables().
> >
> > Just let me add that it doesn't work for all JDBC drivers (at least
not
> > for all in the way it's documented - I remember having quite some
problems
> > with DatabaseMetadata and had to create code that resorted to SELECT
as
> > fallback). The most reliable and simplest way across different DB's
is to
> > really select something from the table IMHO.
> >
>
> I have used this on several DBMS (Oracle, Sybase, MS SQL, MySQL,
Postgres,
> FirebirdSQL, HSQLDB, Cloudscape, DB2, FirstSQL, ThinkSQL) and it works
on all of
> them.
>
> It's a bit tricky to get the parameters right, but I think that is one
of the
> rare JDBC functions where I have not built in any DBMS specific stuff so
far.
>
> What were your problems?

Lemmesee...

I'm sorry, it was not getTables() but getTableInfo(), which is supposed to
yield meta data about a single table. I had to resort to SELECT for
Oracle and MaxDB (former SapDB).

So that probably set a flag "don't trust DatabaseMetaData" in the back of
my head.

Kind regards

    robert