You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Nuno Carvalho <nu...@di.fc.ul.pt> on 2007/07/26 12:14:25 UTC

List existing databases

Hi all,

I need to list the existing databases of derby. Can someone help me  
on this? Is there a way to query the list of available created  
databases or is this information is this information available inside  
the derby engine?

Any help would be appreciated.

Best regards,
--
Nuno Carvalho
University of Lisbon, Portugal
http://lasige.di.fc.ul.pt/~ncarvalho




RE: List existing databases

Posted by Olivier Chedru <oC...@infovista.com>.
Oops, looks like I did not read the question well: I understood
"database tables" instead of "databases".

 

 

From: Olivier Chedru [mailto:oChedru@infovista.com] 
Sent: Thursday, July 26, 2007 12:25 PM
To: Derby Discussion
Subject: RE: List existing databases

 

Hi Nuno,

 

Try using DatabaseMetaData given a connection to your Derby database.
For example :

 

final DatabaseMetaData dmd = connection.getMetaData();

final String schema = "your_schema";

final String[] typeTable = { "TABLE" };

final ResultSet schemaTables = dmd.getTables(null, schema,

                                null, typeTable);

while (schemaTables.next()) {

                String tableName = schemaTables.getString(3));

                System.out.println(tableName);

}

 

 

From: Nuno Carvalho [mailto:nunomrc@di.fc.ul.pt] 
Sent: Thursday, July 26, 2007 12:14 PM
To: Derby Discussion; derby-dev@db.apache.org
Subject: List existing databases

 

Hi all,

 

I need to list the existing databases of derby. Can someone help me on
this? Is there a way to query the list of available created databases or
is this information is this information available inside the derby
engine?

 

Any help would be appreciated.

 

Best regards,

--

Nuno Carvalho

University of Lisbon, Portugal

http://lasige.di.fc.ul.pt/~ncarvalho

 

 

 


RE: List existing databases

Posted by Olivier Chedru <oC...@infovista.com>.
Hi Nuno,

 

Try using DatabaseMetaData given a connection to your Derby database.
For example :

 

final DatabaseMetaData dmd = connection.getMetaData();

final String schema = "your_schema";

final String[] typeTable = { "TABLE" };

final ResultSet schemaTables = dmd.getTables(null, schema,

                                null, typeTable);

while (schemaTables.next()) {

                String tableName = schemaTables.getString(3));

                System.out.println(tableName);

}

 

 

From: Nuno Carvalho [mailto:nunomrc@di.fc.ul.pt] 
Sent: Thursday, July 26, 2007 12:14 PM
To: Derby Discussion; derby-dev@db.apache.org
Subject: List existing databases

 

Hi all,

 

I need to list the existing databases of derby. Can someone help me on
this? Is there a way to query the list of available created databases or
is this information is this information available inside the derby
engine?





Any help would be appreciated.

 

Best regards,

--

Nuno Carvalho

University of Lisbon, Portugal

http://lasige.di.fc.ul.pt/~ncarvalho

 





 


Re: List existing databases

Posted by Nuno Carvalho <nu...@di.fc.ul.pt>.
Ok, that's more or less what I'm doing :)
I just wanted to check if there was some "official" way to get this  
info inside the derby engine.

I also used System.getProperty("file.separator") instead of "/" in  
order to be platform independent.

Thanks!
Nuno

On Jul 27, 2007, at 11:50 , Ole Gunnar Borstad wrote:

> If you have the BasicDatabase instance of the database you want to  
> know the name of, you can do this:
>
> BasicDatabase db;
>
> //this gives the whole path
> String databaseName =  
> org.apache.derby.iapi.services.monitor.Monitor.getMonitor 
> ().getServiceName(db);
>
> //if you only want the name, remove the path
> databaseName = databaseName.substring(databaseName.lastIndexOf("/")  
> + 1);
>
> This should be "safe"... :)
>
> Ole Gunnar
>
>
>
> Siterer Nuno Carvalho <nu...@di.fc.ul.pt>:
>
>> Hi all,
>>
>> thanks for all the answers!
>>
>> I'm working inside the derby engine and I found a way to do this. I
>> found that the BasicDatabase.java receives some properties when its
>> booted and one of them (derby.__rt.serviceDirectory) has the full   
>> path
>> of the database in the directory service, so I get the database  name
>> from it.
>>
>> Can you tell me if this is save? Is there a more clean way to get the
>> database name in the source code?
>>
>> Thanks for all your help!
>>
>> Cheers,
>> nuno
>>
>> On Jul 26, 2007, at 1:35 , Dag H. Wanvik wrote:
>>
>>> Nuno Carvalho <nu...@di.fc.ul.pt> writes:
>>>
>>>> Hi all,
>>>>
>>>> I need to list the existing databases of derby. Can someone help me
>>>> on this? Is there a way to query the list of available created
>>>> databases or is this information is this information available  
>>>> inside
>>>
>>> The databases are booted individually inside a Derby system. The
>>> databases are essentially self contained. Even inspecting the file
>>> system under the default location ${derby.system.home} doesn't
>>> necessarily find all databases created, since they may be created  
>>> and
>>> accessed using explicit paths. It would be possible to list  
>>> databases
>>> *booted* in the present Derby system, but as far as I know there  
>>> is no
>>> such functionality.
>>>
>>> Dag
>>
>>
>>
>> --
>> Nuno Carvalho
>> University of Lisbon, Portugal
>> http://lasige.di.fc.ul.pt/~ncarvalho
>
>



--
Nuno Carvalho
University of Lisbon, Portugal
http://lasige.di.fc.ul.pt/~ncarvalho




Re: List existing databases

Posted by Ole Gunnar Borstad <ol...@stud.ntnu.no>.
If you have the BasicDatabase instance of the database you want to  
know the name of, you can do this:

BasicDatabase db;

//this gives the whole path
String databaseName =  
org.apache.derby.iapi.services.monitor.Monitor.getMonitor().getServiceName(db);

//if you only want the name, remove the path
databaseName = databaseName.substring(databaseName.lastIndexOf("/") + 1);

This should be "safe"... :)

Ole Gunnar



Siterer Nuno Carvalho <nu...@di.fc.ul.pt>:

> Hi all,
>
> thanks for all the answers!
>
> I'm working inside the derby engine and I found a way to do this. I
> found that the BasicDatabase.java receives some properties when its
> booted and one of them (derby.__rt.serviceDirectory) has the full  path
> of the database in the directory service, so I get the database  name
> from it.
>
> Can you tell me if this is save? Is there a more clean way to get the
> database name in the source code?
>
> Thanks for all your help!
>
> Cheers,
> nuno
>
> On Jul 26, 2007, at 1:35 , Dag H. Wanvik wrote:
>
>> Nuno Carvalho <nu...@di.fc.ul.pt> writes:
>>
>>> Hi all,
>>>
>>> I need to list the existing databases of derby. Can someone help me
>>> on this? Is there a way to query the list of available created
>>> databases or is this information is this information available inside
>>
>> The databases are booted individually inside a Derby system. The
>> databases are essentially self contained. Even inspecting the file
>> system under the default location ${derby.system.home} doesn't
>> necessarily find all databases created, since they may be created and
>> accessed using explicit paths. It would be possible to list databases
>> *booted* in the present Derby system, but as far as I know there is no
>> such functionality.
>>
>> Dag
>
>
>
> --
> Nuno Carvalho
> University of Lisbon, Portugal
> http://lasige.di.fc.ul.pt/~ncarvalho




Re: List existing databases

Posted by Nuno Carvalho <nu...@di.fc.ul.pt>.
Hi all,

thanks for all the answers!

I'm working inside the derby engine and I found a way to do this. I  
found that the BasicDatabase.java receives some properties when its  
booted and one of them (derby.__rt.serviceDirectory) has the full  
path of the database in the directory service, so I get the database  
name from it.

Can you tell me if this is save? Is there a more clean way to get the  
database name in the source code?

Thanks for all your help!

Cheers,
nuno

On Jul 26, 2007, at 1:35 , Dag H. Wanvik wrote:

> Nuno Carvalho <nu...@di.fc.ul.pt> writes:
>
>> Hi all,
>>
>> I need to list the existing databases of derby. Can someone help me
>> on this? Is there a way to query the list of available created
>> databases or is this information is this information available inside
>
> The databases are booted individually inside a Derby system. The
> databases are essentially self contained. Even inspecting the file
> system under the default location ${derby.system.home} doesn't
> necessarily find all databases created, since they may be created and
> accessed using explicit paths. It would be possible to list databases
> *booted* in the present Derby system, but as far as I know there is no
> such functionality.
>
> Dag



--
Nuno Carvalho
University of Lisbon, Portugal
http://lasige.di.fc.ul.pt/~ncarvalho




Re: List existing databases

Posted by "Dag H. Wanvik" <Da...@Sun.COM>.
Nuno Carvalho <nu...@di.fc.ul.pt> writes:

> Hi all,
>
> I need to list the existing databases of derby. Can someone help me
> on this? Is there a way to query the list of available created
> databases or is this information is this information available inside

The databases are booted individually inside a Derby system. The
databases are essentially self contained. Even inspecting the file
system under the default location ${derby.system.home} doesn't
necessarily find all databases created, since they may be created and
accessed using explicit paths. It would be possible to list databases
*booted* in the present Derby system, but as far as I know there is no
such functionality.

Dag