473,757 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;

PreparedStateme nt st= con.prepareStat ement(sql);
st.execute(sql) ; // tried regular Statement class also

}
catch (SQLException e)
{
System.out.prin tln("Error in declaring the cursor");
e.printStackTra ce();
}

try
{
String sql2 = "load from cur of cursor insert into schema.customer
nonrecoverable" ;
Statement st1=con.createS tatement();
st1.execute(sql 2);
}
catch (SQLException e1)
{
System.out.prin tln("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.jdb c.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.jdb c.app.SQLExcept ionGenerator.th row_SQLExceptio n(SQLExceptionG enerator.java(C ompiled
Code))
at
COM.ibm.db2.jdb c.app.SQLExcept ionGenerator.th row_SQLExceptio n(SQLExceptionG enerator.java:2 17)
at
COM.ibm.db2.jdb c.app.SQLExcept ionGenerator.ch eck_return_code (SQLExceptionGe nerator.java:44 9)
at
COM.ibm.db2.jdb c.app.DB2Statem ent.execute2(DB 2Statement.java :857)
at
COM.ibm.db2.jdb c.app.DB2Statem ent.execute(DB2 Statement.java: 530)
at
PKG603011246378 44.InitControl. initCustomer(In itControl.java: 344)
at
PKG603011246378 44.InitControl. initControl(Ini tControl.java:4 9)

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


LOAD is not a SQL statement but rather a DB2 command. Thus, you cannot use
any of the JDBC methods like Statement.execu te() 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.z ip" 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

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

Similar topics

3
4016
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 found some things that I don't understand so if any one could shed any light it would be much appreciated. I have posted these at the end.
5
6055
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 update_salary (in emp_number char(6), in rate integer) language sql begin update employee
3
2864
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 pgpa.db2 > DB21034E The command was processed as an SQL statement because it was not a > valid Command Line Processor command. During SQL processing it returned: > SQL0035N The file "P2340425.msg" cannot be opened. What does this message mean?...
8
7944
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 created a temporary database with a tables space. Verified that DECLARE GLOBAL TEMPORARY TABLE TEMP (A INTEGER); INSERT INTO SESSION.TEMP VALUES(10); SELECT A FROM SESSION.TEMP; works from a query tool.
1
8268
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 Command Line Processor command. During SQL processing it returned: SQL0418N A statement contains a use of a parameter marker that is not valid. LINE NUMBER=48. SQLSTATE=42610.
1
13669
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 procedure============= Create PROCEDURE get_timedout_scripts (
1
7530
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 ( ) DYNAMIC RESULT SETS 1 ------------------------------------------------------------------------
0
1646
by: jasonlyt | last post by:
Can anyone advise me how to run Runstats and Load command in a stored procedure? Thanks.
2
1791
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"): Imports System.Data.SqlClient Imports System.Data Partial Class pages_default
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.