473,769 Members | 6,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to integrate ForUpdate iterator in Development Center

Hi,

I would like to build the inParams SQLJ sample procedure from the
Development Center.

if I declare a #sql public iterator SpIterat, the Development Center
complains this should be in a separate file.
if I declare a #sql iterator SpIterat, the Development Center complains the
statements #sql [ctx] updateIterator are not Java ...

My problem is: how do I integrate the ForUpdate iterator ? It should be in a
class that needs to be incorporated into my JAR but I don't see how

Thanks for your help,

Eric
import java.sql.*; // JDBC classes
import java.io.*; // Input/Output classes
import java.math.BigDe cimal; // Packed Decimal class
import sqlj.runtime.*;
import sqlj.runtime.re f.*;

===> sqlj.runtime.Fo rUpdate;
===> #sql public iterator SpIterat implements ForUpdate(doubl e);

#sql context SpContext;

#sql iterator SpServerSalary( double);
#sql iterator SpServerEmploye es(String, String, double);

///////
// SQLj stored procedure is in this class
///////
public class SpServer
{
//*************** *************** *************** *************** *************
// Stored Procedure: inParams
//
// Purpose: Updates salaries of employees in department 'inDepartment'
// using inputs inLowSal, inMedSal, inHighSal as
// salary raise/adjustment values.
//
// Parameters:
//
// IN: inLowSal - new salary for low salary employees
// inMedSal - new salary for mid salary employees
// inHighSal - new salary for high salary employees
// inDepartment - department to use in SELECT predicate
// OUT: (none)
//

//*************** *************** *************** *************** *************
public static void inParams(double inLowSal,
double inMedSal,
double inHighSal,
String inDepartment) // CHAR(3)
throws SQLException
{
String errorLabel = null;
int errorCode = 0; // SQLCODE = 0 unless SQLException occurs

SpContext ctx = null;
double salary;
String cursorName;
SpIterat updateIterator;

// initialize variables
salary = 0;
cursorName = "";

try
{
ctx = new SpContext("jdbc :default:connec tion", false);

errorLabel = "DECLARE ITERATOR";
#sql [ctx] updateIterator = {SELECT CAST(salary AS DOUBLE)
FROM employee
WHERE workdept = :inDepartment};

errorLabel = "FETCH FIRST ROW";
#sql {FETCH :updateIterator INTO :salary};

if (updateIterator .endFetch())
{
// iterator contains no data, so return SQLCODE 100 to client
errorLabel = "100 : NO DATA FOUND";
}
else
{
while (!updateIterato r.endFetch())
{
if (inLowSal > salary)
{
errorLabel = "UPDATE -- LOW CASE";
#sql [ctx] {UPDATE employee SET salary = :inLowSal
WHERE CURRENT OF :updateIterator };
}
else if (inMedSal > salary)
{
errorLabel = "UPDATE -- MEDIUM CASE";
#sql [ctx] {UPDATE employee SET salary = :inMedSal
WHERE CURRENT OF :updateIterator };
}
else if (inHighSal > salary)
{
errorLabel = "UPDATE -- HIGH CASE";
#sql [ctx] {UPDATE employee SET salary = :inHighSal
WHERE CURRENT OF :updateIterator };
}
else
{
errorLabel = "UPDATE -- FINAL CASE";
#sql [ctx] {UPDATE employee SET salary = (salary * 1.10)
WHERE CURRENT OF :updateIterator };
}
#sql {FETCH :updateIterator INTO :salary};
}
}
updateIterator. close();
ctx.close();
}
catch (SQLException sqle)
{
if( ctx != null )
{
try { ctx.close(); } catch( Exception e ) {}
}

errorCode = sqle.getErrorCo de();
if (errorLabel.equ alsIgnoreCase(" 100 : NO DATA FOUND"))
throw new SQLException(sq le.getMessage() );
else
throw new SQLException(er rorCode + " : " + errorLabel + " FAILED");
}
} // inParams
} // SpServer
Nov 12 '05 #1
0 1847

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

Similar topics

2
7915
by: Claude Shea | last post by:
Is DB2 Development Center an addon product that I have to download or purchase separately? I can't seem to find it in any of my downloads or on any of my CDs. Is it available for all versions of DB2? I currently have two versions of DB2. My production environment is DB2 UDB WSUE V8.1 on a Redhat Linux 7.2 . Currently in the process of creating a new production environment which is DB2 UDB Workgroups V8.2 which is installed on Suse 9...
3
1823
by: Henry Reardon | last post by:
Can someone remind me how to re-install the Development Center? I was playing with the Environment Settings a bit the other day and, ever since, it hasn't worked right. I can create a new Project but that's all I can do; the File and Edit menus are grayed out and I can't seem to find anything that will re-enable them. I upgraded from DB2 (LUW) Version 7.2 to Version 8.2 (FP7) on Friday and applied Fixpack 8 on Saturday. I'm running...
1
1810
by: Henry Reardon | last post by:
I have been having problems with the Development Center for several days now. It seemed to be working fine when I initially installed DB2 (LUW) Version 8 (FP7) and upgraded to FP8, except that I kept getting SQL1131 whenever I tried to prepared a stored procedure. As a result, I completely deleted DB2 and reinstalled version 8 and upgraded to FP8. At that point, I experimented a bit with some of the Environment Settings, particularly the...
0
1548
by: fblake | last post by:
Brussels, Belgium and Sunnyvale, Calif., – July 2007 – Active Up today announced today that it has entered into an agreement with Commtouch® (NASDAQ:CTCH) to license Anti-Spam and Zero-Hour™ Virus Outbreak Detection technology to combat escalating spam and virus threats. ActiveUp.MailSystem is the first full-featured suite of .Net components on the market to offer built-in Commtouch Anti-Spam and Zero-Hour Virus Outbreak Detection...
0
9589
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
9423
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
10216
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...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5309
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.