Unix Technical Forum

Batch execution via JDBC (temp table problem)

This is a discussion on Batch execution via JDBC (temp table problem) within the Informix forums, part of the Database Server Software category; --> Hi, I work with with dynamically generated SQL statements (may be a thousand or more). When working with Postgres ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 09:31 AM
m.bisping@gmx.de
 
Posts: n/a
Default Batch execution via JDBC (temp table problem)

Hi,

I work with with dynamically generated SQL statements (may be a
thousand or more).
When working with Postgres I can simply use a single JDBC statement and
dispatch them all.
However, when trying to do the same thing with Informix (9.3) the JDBC
driver complains that temp tables are not known.

This can be reproduced the following way:
Statement stm = con.createStatement();
stm.execute("create temp table testmb(col1 integer);insert into
testmb values (1);");
//normally more SQL would follow which makes use of the temp tables
--> The specified table (testtab) is not in the database.

When splitting it up into batch-Statements, it works.
stm.addBatch("create temp table testmb(col1 integer);");
stm.addBatch("insert into testmb values (1);");
stm.executeBatch();

However, my SQL is very dynamically created, and so I would not like
to parse manually with a StringTokenizer over all semicolons, since
semicolons might be contained in a char value (select val1||';'||val2
from xy).

Is there an elegant way to achieve a batch-execution?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 09:33 AM
Jonathan Leffler
 
Posts: n/a
Default Re: Batch execution via JDBC (temp table problem)

m.bisping@gmx.de wrote:
> Hi,
>
> I work with with dynamically generated SQL statements (may be a
> thousand or more).
> When working with Postgres I can simply use a single JDBC statement and
> dispatch them all.
> However, when trying to do the same thing with Informix (9.3) the JDBC
> driver complains that temp tables are not known.
>
> This can be reproduced the following way:
> Statement stm = con.createStatement();
> stm.execute("create temp table testmb(col1 integer);insert into
> testmb values (1);");
> //normally more SQL would follow which makes use of the temp tables
> --> The specified table (testtab) is not in the database.
>
> When splitting it up into batch-Statements, it works.
> stm.addBatch("create temp table testmb(col1 integer);");
> stm.addBatch("insert into testmb values (1);");
> stm.executeBatch();
>
> However, my SQL is very dynamically created, and so I would not like
> to parse manually with a StringTokenizer over all semicolons, since
> semicolons might be contained in a char value (select val1||';'||val2
> from xy).
>
> Is there an elegant way to achieve a batch-execution?


Do the CREATE TEMP TABLE in a separate statement.

Once the table exists, combine as many inserts as you like into as few
statements as you like - beware, the total length must be less than 64 KB.

Consider the benefits of an INSERT cursor - which might not be available
via the JDBC interface. Or using a prepared INSERT statement with
question marks as placeholders for the values, and execute it
repeatedly, providing new values for each row.


--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.01 -- http://dbi.perl.org/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com