db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: checking if table exists
Date Thu, 04 Oct 2007 12:23:04 GMT
Wolf Bublitz wrote:
> That`s the way it should be, but does not work either.
> 
>         String[] names = { "TABLE" };
>         ResultSet result = null;
>         DatabaseMetaData metadata = null;
> 
>         try {
>             metadata = dbConnection.getMetaData();
>             result = metadata.getTables(null, null, null, names);
>             while(result.next()) {
>                 System.out.println(result.getString("TABLE_NAME"));
>             }
>         } catch(java.sql.SQLException e) {
>             e.printStackTrace();
>         }
> 

Hello,

I added the code required to obtain the connection to the the code 
snippet above. It compiled, I ran it and it showed all the four tables I 
created in my database. If I replaced 'names' in the getTables-call with 
'null' I also got all the system tables.

How do you obtain the connection in your code? (variable 'dbConnection')
 From where do you run the code? (NetBeans, command line, etc)

Since the code works as written in the previous mail, my first guess 
would be that the wrong database is accessed or that a new one is created.

Depending on further information you give, we can consider other 
possibilities.



regards,
-- 
Kristian

> 
> 
> Am 03.10.2007 um 15:44 schrieb Bryan Pendleton:
> 
>>>             while((result.next()) & (tableExists = false)) {
>>
>> Is this possibly a typo? Make sure it says:
>>
>>              while((result.next()) && (tableExists == false)) {
>>
>> You want to do a logical and, not a bitwise and; also you want
>> to do a comparison, not an assignment.
>>
>> thanks,
>>
>> bryan
>>
> 


Mime
View raw message