I did a workaround... I used the Pattern class to split into token on the ;,
and then looped through each statement to run it. Worked, and fairly clean.
--------------------------------------------------
From: "Knut Anders Hatlen" <[email protected]>
Sent: Thursday, October 08, 2009 5:36 PM
To: "Derby Discussion" <[email protected]>
Subject: Re: Create DB Structure in one statement
bruehlicke <[email protected]> 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
<[email protected]> 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