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 Ot ten Thije <O....@topdesk.com> on 2006/08/04 16:35:03 UTC

Multiple statements in a single execute()

I am integrating derby  into an existing appliction, which uses a 
template system to be able to access multiple different RDBMS'es. I've 
been trying to make a workaround for derby's current lack of support for 
the ALTER TABLE DROP COLUMN and most of the ALTER TABLE ALTER COLUMN - 
statements. Unfortunately, the template system used does not allow calls 
to Java (or anything else other than itself, for that matter), so any 
manipulation must be executable with one single statement.execute().

I thought I'd solve this by simply using a statement seperator like the 
semi-colon, but after extensively searching the docs and the web I've 
been unable to find out what - if any - derby's separation character is. 
So my question is: _is_ there a separation character at all, and if 
there isn't, what else could I do to execute multiple statements with 
just one execute()? Are there any indications on whether this 
functionality will be implemented in a future release ?


Perhaps an example helps to add some clarity. Instead of doing this:

(new Statement("CREATE TABLE tablename (<fields>)")).execute();
(new Statement("INSERT INTO tablename (<fields>) VALUES 
(<values>)")).execute();

I need to be able to do something like this:

(new Statement("CREATE TABLE tablename (<fields>); INSERT INTO tablename 
(<fields>) VALUES (<values>) ")).execute();


I'd very much appreciate your help on this,

Yours sincerely,


Ot ten Thije

Re: Multiple statements in a single execute()

Posted by Jean-Francois Dignard <jf...@broadsoft.com>.
I think you need to do something like this:

Using the statement returned by your connection.createStatement();
You should be able to do:
myStatement.addBatch("CREATE TABLE tablename (<fields>)");
myStatement.addBatch(""INSERT INTO tablename (<fields>) VALUES (<values>)");

myStatement.executeBatch();

This will do the same thing as if you used semi-colons.

Let me know if this helped you,

JF

Ot ten Thije wrote:
> I am integrating derby  into an existing appliction, which uses a 
> template system to be able to access multiple different RDBMS'es. I've 
> been trying to make a workaround for derby's current lack of support 
> for the ALTER TABLE DROP COLUMN and most of the ALTER TABLE ALTER 
> COLUMN - statements. Unfortunately, the template system used does not 
> allow calls to Java (or anything else other than itself, for that 
> matter), so any manipulation must be executable with one single 
> statement.execute().
>
> I thought I'd solve this by simply using a statement seperator like 
> the semi-colon, but after extensively searching the docs and the web 
> I've been unable to find out what - if any - derby's separation 
> character is. So my question is: _is_ there a separation character at 
> all, and if there isn't, what else could I do to execute multiple 
> statements with just one execute()? Are there any indications on 
> whether this functionality will be implemented in a future release ?
>
>
> Perhaps an example helps to add some clarity. Instead of doing this:
>
> (new Statement("CREATE TABLE tablename (<fields>)")).execute();
> (new Statement("INSERT INTO tablename (<fields>) VALUES 
> (<values>)")).execute();
>
> I need to be able to do something like this:
>
> (new Statement("CREATE TABLE tablename (<fields>); INSERT INTO 
> tablename (<fields>) VALUES (<values>) ")).execute();
>
>
> I'd very much appreciate your help on this,
>
> Yours sincerely,
>
>
> Ot ten Thije
>