You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Teja <te...@synapse.ws> on 2007/08/09 22:31:07 UTC
check if DB exists already?
How do I check if the database exists already? I know create=true in the
connection url creates if db doesn't exist and throws a SQLWarning if exists
already, but is there a way to know for sure that a database exists already
before connecting?
--
View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12080193
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: check if DB exists already?
Posted by Teja <te...@synapse.ws>.
Bernt,Kathy
Thanks for your replies.. I will do as suggested.
Teja wrote:
>
> If the database doesn't exist, I need to initalize it, create some tables
> and stuff... What should I do instead?
>
>
> Daniel John Debrunner-2 wrote:
>>
>> Teja wrote:
>>> How do I check if the database exists already? I know create=true in the
>>> connection url creates if db doesn't exist and throws a SQLWarning if
>>> exists
>>> already, but is there a way to know for sure that a database exists
>>> already
>>> before connecting?
>>
>> Why not just attempt a connection? What do you gain by knowing if the
>> database exists or not?
>>
>> Dan.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12090556
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: check if DB exists already?
Posted by Kathey Marsden <km...@sbcglobal.net>.
Teja wrote:
> If the database doesn't exist, I need to initalize it, create some tables and
> stuff... What should I do instead?
>
You could try to connect without create=true, if you get an SQLState
XJ004 no database is there.
ij> connect 'jdbc:derby:mydb';
ERROR XJ004: Database 'mydb' not found.
ij>
Kathey
Re: check if DB exists already?
Posted by Teja <te...@synapse.ws>.
Brenty, Kathy
Thanks a lot for your time. I will do as suggested.
Teja wrote:
>
> If the database doesn't exist, I need to initalize it, create some tables
> and stuff... What should I do instead?
>
>
> Daniel John Debrunner-2 wrote:
>>
>> Teja wrote:
>>> How do I check if the database exists already? I know create=true in the
>>> connection url creates if db doesn't exist and throws a SQLWarning if
>>> exists
>>> already, but is there a way to know for sure that a database exists
>>> already
>>> before connecting?
>>
>> Why not just attempt a connection? What do you gain by knowing if the
>> database exists or not?
>>
>> Dan.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12090553
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: check if DB exists already?
Posted by "Bernt M. Johnsen" <Be...@Sun.COM>.
>>>>>>>>>>>> Teja wrote (2007-08-09 14:09:27):
>
> If the database doesn't exist, I need to initalize it, create some tables and
> stuff... What should I do instead?
try {
c = DriverManager.getConnection('...url...');
} catch (SQLException.....) {
c = DriverManager.getConnection('...url...;create=true');
.... initialize it, create tables and stuff
}
Just fill in the details. This should be fairly straight forward.
>
>
> Daniel John Debrunner-2 wrote:
> >
> > Teja wrote:
> >> How do I check if the database exists already? I know create=true in the
> >> connection url creates if db doesn't exist and throws a SQLWarning if
> >> exists
> >> already, but is there a way to know for sure that a database exists
> >> already
> >> before connecting?
> >
> > Why not just attempt a connection? What do you gain by knowing if the
> > database exists or not?
> >
> > Dan.
> >
> >
>
> --
> View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12080833
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>
Re: check if DB exists already?
Posted by Teja <te...@synapse.ws>.
If the database doesn't exist, I need to initalize it, create some tables and
stuff... What should I do instead?
Daniel John Debrunner-2 wrote:
>
> Teja wrote:
>> How do I check if the database exists already? I know create=true in the
>> connection url creates if db doesn't exist and throws a SQLWarning if
>> exists
>> already, but is there a way to know for sure that a database exists
>> already
>> before connecting?
>
> Why not just attempt a connection? What do you gain by knowing if the
> database exists or not?
>
> Dan.
>
>
--
View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12080833
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Re: check if DB exists already?
Posted by Daniel John Debrunner <dj...@apache.org>.
Teja wrote:
> How do I check if the database exists already? I know create=true in the
> connection url creates if db doesn't exist and throws a SQLWarning if exists
> already, but is there a way to know for sure that a database exists already
> before connecting?
Why not just attempt a connection? What do you gain by knowing if the
database exists or not?
Dan.
Re: check if DB exists already?
Posted by Teja <te...@synapse.ws>.
I have to say that really sucks.. They could've easily comeup with a system
function that would check if a db exists or not instead of the user doing
directory and file checks. But then, it is free, so I cann't complain much..
dmclean62 wrote:
>
> A Derby database is a directory containing a fairly distinctive set of
> files. You could use file system operations to see if a directory by that
> name exists and then check to see if it has the right files.
>
> Donald
>
> -------------- Original message ----------------------
> From: Teja <te...@synapse.ws>
>>
>> How do I check if the database exists already? I know create=true in the
>> connection url creates if db doesn't exist and throws a SQLWarning if
>> exists
>> already, but is there a way to know for sure that a database exists
>> already
>> before connecting?
>> --
>> View this message in context:
>> http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12080193
>> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>>
>
>
>
--
View this message in context: http://www.nabble.com/check-if-DB-exists-already--tf4245044.html#a12080523
Sent from the Apache Derby Users mailing list archive at Nabble.com.