473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to load a cursor from a stored procedure in DB2

Hi,
I am trying to declare and cursor and thn load from that cursor into
another table. Since I have almost 4 million records, I cant do it
without the cursor which reduces the time by almost 1/10th.
I tried to create a sql statement for "load from cursor cur insert into
table name" using java stored procedure, but this isnt recognised by
sql since load isnt a sql keyword. So whats the solution to this. I
have to do it programatically rahter than going to db2clp everytime I
want to load data.
Any suggestions are welcome..
This is the excerpt of the code I am trying to build
try
{
String sql="declare cur cursor for SELECT * from tablename;

PreparedStatement st= con.prepareStatement(sql);
st.execute(sql); // tried regular Statement class also

}
catch (SQLException e)
{
System.out.println("Error in declaring the cursor");
e.printStackTrace();
}

try
{
String sql2 = "load from cur of cursor insert into schema.customer
nonrecoverable";
Statement st1=con.createStatement();
st1.execute(sql2);
}
catch (SQLException e1)
{
System.out.println("Error loading form the cursor");
}

Throws exception at both the places. The log looks like this:

SELECT * from tablename
Error in declaring the cursor
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/6000] SQL0104N An
unexpected token "load from cur of cursor" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".
SQLSTATE=42601

at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(SQLExceptionGenerator.java(Compiled
Code))
at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(SQLExceptionGenerator.java:217)
at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_r eturn_code(SQLExceptionGenerator.java:449)
at
COM.ibm.db2.jdbc.app.DB2Statement.execute2(DB2Stat ement.java:857)
at
COM.ibm.db2.jdbc.app.DB2Statement.execute(DB2State ment.java:530)
at
PKG60301124637844.InitControl.initCustomer(InitCon trol.java:344)
at
PKG60301124637844.InitControl.initControl(InitCont rol.java:49)

Mar 21 '06 #1
10 10849
technocrat wrote:
try
{
String sql2 = "load from cur of cursor insert into schema.customer
nonrecoverable";
Statement st1=con.createStatement();
st1.execute(sql2);
}


LOAD is not a SQL statement but rather a DB2 command. Thus, you cannot use
any of the JDBC methods like Statement.execute() to start a LOAD. You will
have to resort to the DB2 API, which implies something like JNI, or you
wrap the LOAD into a procedure (as was done here http://tinyurl.com/9gnlo
for import) and call the procedure (CALL is a SQL statement). Yet another
alternative would be to create a SQL script and execute that script through
the DB2 CLP.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Mar 21 '06 #2
Hi Knut ,
thanks for the repply, i tried find the code in the url u gave me but
i cudnt find anything there...which imprt are u trying to mention? I
somehow dint find anything there.
Moreover can u give me more insight on the DB2API?? how to find that
and how can i use it or if u have an example if u can send it to me it
would be very helpfuil to me. I have already spent almost 2 days on
this thing...
Any help would be appreciated. Thanks

Mar 21 '06 #3
technocrat wrote:
Hi Knut ,
thanks for the repply, i tried find the code in the url u gave me but
i cudnt find anything there...which imprt are u trying to mention? I
somehow dint find anything there.
The code is in the "db2migration.zip" archive. Have a look at the
"truncate" procedure.
Moreover can u give me more insight on the DB2API?? how to find that
and how can i use it or if u have an example if u can send it to me it
would be very helpfuil to me. I have already spent almost 2 days on
this thing...


The complete API provided by DB2 is documented here: http://tinyurl.com/18r

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Mar 21 '06 #4
That's not going to work because DB2 LOAD command is not a SQL
statement and hence could not be driven by jdbc.

-Eugene

Mar 21 '06 #5
Well ,Thanks will look into that..

Mar 21 '06 #6
create table tablename(c1 int);
insert into tablename values 1, 2, 3, 4, 5;
create table schema.customer like tablename;

CALL sysproc.db2load(1, 'declare cur cursor for SELECT * from tablename',
'load from cur of cursor insert into schema.customer
nonrecoverable',
?, '', ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL);

Enjoy
Serge

PS: And no... It's not documented.. but if it's good enough for the GUI
to use ....

PPS: Not sure.. may need FP9 or so...

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 21 '06 #7
Any idea what I am supposed to enter for ?s.
This is the ideal way for me to implemetn since its a sql call but only
if i can know wht to enter for questionmarks
Any help appreciated

Mar 22 '06 #8
well that worked..that was great..thanks a lot serge...i really
appreciate your help..!

Mar 22 '06 #9
Serge,

But *not documented* should also mean not supported by IBM, right? :-)
So how about using that solution at a customer site -- there are many
occasions where load from SQL would've made a project implementation
much easier.

Regards,
-Eugene

Mar 22 '06 #10
Eugene F wrote:
But *not documented* should also mean not supported by IBM, right? :-)
So how about using that solution at a customer site -- there are many
occasions where load from SQL would've made a project implementation
much easier.

Do you believe in the Easterbunny? I do.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 22 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: aaj | last post by:
SQL SERVER 2000 Hi all This is my first attempt at writing a stored procedure. I have managed to get it working but its unlikely to be the best way of handling the problem. While writing it I...
5
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
3
by: N. Shamsundar | last post by:
A stored procedure (listed below) that loads fine on Windows XP with DB2 V8.1.4 Express fails to load on Linux DB2 Workgroup server V8.1, with the following message: > sh-2.05a$ db2 -td@ -f...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
1
by: UDBDBA | last post by:
Hi: How can one call SYSPROC.DB2LOAD procedure within a SQL stored procedure. I get the following error: DB21034E The command was processed as an SQL statement because it was not a valid...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
1
by: peaceburn | last post by:
Hi, I'm gonna pull my hair in the coming days with these DB2 stored procedures. So the issue, let's assume a simple stored procedure like this : CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( )...
0
by: jasonlyt | last post by:
Can anyone advise me how to run Runstats and Load command in a stored procedure? Thanks.
2
by: Mark B | last post by:
What amendments to the ASP.NET 3.5. VB code below output the MSSQL stored procedure dataset result to XML (as a response stream)? (I also guessing to use Response.ContentType = "text/xml"): ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.