db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Create DB Structure in one statement
Date Thu, 08 Oct 2009 21:36:57 GMT
bruehlicke <bruehlicke@gmail.com> writes:

>            Statement s = _connection.createStatement();
>
>             s.execute(
>                     "CREATE TABLE TABLE1 (" +
>                     "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS
> AS IDENTITY (START WITH 1, INCREMENT BY 1)," +
>                     "NAME VARCHAR(80) NOT NULL," +
>                     "VALUE VARCHAR(12) NOT NULL," +
>                     "DESCRIPTION VARCHAR(255)," +
>                     "CREATED_BY VARCHAR(40) DEFAULT USER," +
>                     "CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
>                     "LAST_UPDATED TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
>                     ")" + ";" +
>                     "CREATE TABLE TABLE2 (" +
>                     "ID BIGINT NOT NULL PRIMARY KEY GENERATED ALWAYS
> AS IDENTITY (START WITH 1, INCREMENT BY 1)," +
>                     "NAME VARCHAR(80) NOT NULL," +
>                     "VALUE VARCHAR(12) NOT NULL," +
>                     "DESCRIPTION VARCHAR(255)," +
>                     "CREATED_BY VARCHAR(40) DEFAULT USER," +
>                     "CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP," +
>                     "LAST_UPDATED TIMESTAMP DEFAULT CURRENT_TIMESTAMP" +
>                     ")"
>              );
>
>
> Should work - this would create 2 table in one statement.

If this doesn't work (I didn't think we supported this, but I haven't
actually tested), you could take a look at ij's API at
http://db.apache.org/derby/javadoc/publishedapi/jdbc4/org/apache/derby/tools/ij.html,
in particular the runScript() methods which allow you to pass in
multiple statements through a stream.

> On Thu, Oct 8, 2009 at 2:38 PM, Rick Schneider
> <rickschneider17@hotmail.com> wrote:
>> OK.. I am trying to create my entire DB structure (about 6 tables or so) in
>> a single JDBC Statement to embedded Derby 10.5.  I keep running into issues
>> with the proper syntax to separate the different statements.  Is there a way
>> to do this other than running multiple statements?
>>
>> Thanks

-- 
Knut Anders

Mime
View raw message