db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernt M. Johnsen" <Bernt.John...@Sun.COM>
Subject Re: Equivalent of SQL "DROP TABLE IF EXISTS MY_TABLE" ?
Date Mon, 26 Sep 2005 10:39:23 GMT
>>>>>>>>>>>> Bernt M. Johnsen wrote (2005-09-26 12:09:26):
> >>>>>>>>>>>> wolfgang127us@yahoo.co.jp wrote (2005-09-26
18:11:26):
> > Hi there,
> > 
> > To initialize my database, I want to use an SQL 
> > equivalent of "DROP TABLE IF EXISTS MY_TABLE" .
> > 
> > I've tried it but of course didn't work
> > 
> > Does Derby support this kinda SQL or Is there any workaround
> > I can drop a table if it exists ??
> 
> One way could be:
>         try {
>             stmt.executeUpdate("DROP TABLE MY_TABLE");
>         } catch (SQL_Exception e) {
>             if (!e.getSQLState().equals("proper SQL-state for table does not exist"))

In Derby it is:
             if (!e.getSQLState().equals("42Y55"))

-- 
Bernt Marius Johnsen, Database Technology Group, 
Sun Microsystems, Trondheim, Norway

Mime
View raw message