You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-user@db.apache.org by Thorbjørn Ravn Andersen <th...@gmail.com> on 2005/11/07 11:47:20 UTC

[Howto?] Creating a new Derby database with ddlutils.

I want my ddlutils program to create a fresh database in Derby when 
starting, but I cannot quite figure out how to do this correctly.

I understand that I need to use something similar to:

        EmbeddedDataSource dataSource = new EmbeddedDataSource();


        DataSource ds = dataSource;

        Platform platform = PlatformFactory.createNewPlatformInstance(ds);


        platform.createDatabase("org.apache.derby.jdbc.ClientDriver", dbURL,

                "me", "mine", Collections.EMPTY_MAP);

        System.out.print("Created");



but unfortunately the creation of the platform in order to get the 
createDatabase method, results in a Derby connection being made, which 
fails because there is no databases corresponding. 

I therefore have a chicken and egg problem :(

Is there any particular reason that the createDatabase method isn't static?

-- 
  Thorbjørn

Re: [Howto?] Creating a new Derby database with ddlutils.

Posted by Thomas Dudziak <to...@gmail.com>.
On 11/7/05, Thorbjørn Ravn Andersen <th...@gmail.com> wrote:

> I want my ddlutils program to create a fresh database in Derby when
> starting, but I cannot quite figure out how to do this correctly.
>
> I understand that I need to use something similar to:
>
>         EmbeddedDataSource dataSource = new EmbeddedDataSource();
>         DataSource ds = dataSource;
>         Platform platform = PlatformFactory.createNewPlatformInstance(ds);

You should not create the platform via the datasource because this
will fail as the platform factory will try to determine the database
type by connecting to it.
Rather, create it by specifying the database type or the jdbc driver &
url as the argument(s).

>         platform.createDatabase("org.apache.derby.jdbc.ClientDriver", dbURL,
>                 "me", "mine", Collections.EMPTY_MAP);

This should work as long as the platform is correctly for Derby.

Tom