dbTalk Databases Forums  

is there any better way to insert into db2 tables from JDBC resultsetor any other in memory data?

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss is there any better way to insert into db2 tables from JDBC resultsetor any other in memory data? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Yonghang Wang
 
Posts: n/a

Default is there any better way to insert into db2 tables from JDBC resultsetor any other in memory data? - 07-19-2011 , 09:34 PM






suppose I have a result set which contains data needed to be inserted
into a db2 tables, the obvious options are:
1. insert every row by a INSERT
2. group insert with "values(),(),," need to be careful to avoid the
sql limit of 2M.

any better idea? so far I can only rely on option 2.

Thanks.

Reply With Quote
  #2  
Old   
Manoj Sutar
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-29-2011 , 04:19 PM






On Jul 19, 7:34*pm, Yonghang Wang <wyh... (AT) gmail (DOT) com> wrote:
Quote:
suppose I have a result set which contains data needed to be inserted
into a db2 tables, the obvious options are:
1. insert every row by a INSERT
2. group insert with "values(),(),," need to be careful to avoid the
sql limit of 2M.

any better idea? *so far I can only rely on option 2.

Thanks.
How about loading from cursor?

Cheers,
Manoj Sutar

Reply With Quote
  #3  
Old   
MarkB
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-30-2011 , 12:30 PM



On Jul 20, 6:34*am, Yonghang Wang <wyh... (AT) gmail (DOT) com> wrote:
Quote:
suppose I have a result set which contains data needed to be inserted
into a db2 tables, the obvious options are:
1. insert every row by a INSERT
2. group insert with "values(),(),," need to be careful to avoid the
sql limit of 2M.

any better idea? *so far I can only rely on option 2.

Thanks.
Hi Yonghang,

You can combine these 2 methods with batch queries as well:
http://publib.boulder.ibm.com/infoce..._tjvjcbqu.html

Sincerely,
Mark B.

Reply With Quote
  #4  
Old   
Yonghang Wang
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-30-2011 , 10:31 PM



yes, thanks. it's interesting how much time it may save by prepared stmt. for this kind of workload, as the real executing part is only a INSERT.

just curious, is there anybody from IBM lab can show us whether it's possible to "declare cursor on JDBC ResultSet" or c/c++ alternatives.

Reply With Quote
  #5  
Old   
Yonghang Wang
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-30-2011 , 10:33 PM



Manoj, yes, it's the very thing I want to find... here the source is not db2 so we say the source is just JDBC resultset.

Reply With Quote
  #6  
Old   
MarkB
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-31-2011 , 07:24 AM



On Aug 31, 7:31*am, Yonghang Wang <wyh... (AT) gmail (DOT) com> wrote:
Quote:
yes, thanks. it's interesting how much time it may save by prepared stmt.for this kind of workload, as the real executing part is only a INSERT.

just curious, is there anybody from IBM lab can show us whether it's possible to "declare cursor on JDBC ResultSet" or c/c++ alternatives.
I'm not from the IBM lab but I can tell you that it's not possible
In CLI (but not in JDBC) you can use column-wise array input:
http://publib.boulder.ibm.com/infoce.../t0007268.html
If you're able to save the contents of your ResultSet to some csv file
on the db2 server, you can load it with IMPORT/LOAD utilities via
ADMIN_CMD routine.

Reply With Quote
  #7  
Old   
Serge Rielau
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-31-2011 , 08:11 AM



Yonghang Wang,

You can create a procedure which takes an ARRAYs of scalar values as
input (you need to create type first).
Then do the INSERT within that procedure.

Something like this:

CREATE TYPE varchar_arr AS VARCHAR(4000) ARRAY[];

CREATE TYPE int_arr AS INTEGER ARRAY[];

--#SET TERMINATOR @
CREATE OR REPLACE PROCEDURE insert_t(pk int_arr, val varchar_arr)
BEGIN
INSERT INTO t(pk, val) SELECT * FROM UNNEST(pk, val) AS T(pk, val);
END
@
--#SET TERMINATOR ;

JDBC can pass arrays to a CALL.
I think (?) in 9.7.4 you can also pass an array of rows.

Cheers
Serge
--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

Reply With Quote
  #8  
Old   
Yonghang Wang
 
Posts: n/a

Default Re: is there any better way to insert into db2 tables from JDBCresultset or any other in memory data? - 08-31-2011 , 08:34 PM



thanks,really cool. This way I can declare the cursor for load.

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.