473,651 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DECLARE/FETCH USING JAVA..(POSITION ED UPDATE)

HOW CAN THIS BE DONE IN JAVA??? THIS IS POSITIONED UPDATE
EXEC SQL DECLARE C1 CURSOR FOR
SELECT *
FROM EMPLOYEE
FOR UPDATE OF JOB;

EXEC SQL OPEN C1;

EXEC SQL FETCH C1 INTO ... ;
if ( strcmp (change, "YES") == 0 )
EXEC SQL UPDATE EMPLOYEE
SET JOB = :newjob
WHERE CURRENT OF C1;

EXEC SQL CLOSE C1;

May 25 '06 #1
2 3944
In article <11************ **********@38g2 000cwa.googlegr oups.com>,
su************@ gmail.com says...
HOW CAN THIS BE DONE IN JAVA??? THIS IS POSITIONED UPDATE
EXEC SQL DECLARE C1 CURSOR FOR
SELECT *
FROM EMPLOYEE
FOR UPDATE OF JOB;

EXEC SQL OPEN C1;

EXEC SQL FETCH C1 INTO ... ;
if ( strcmp (change, "YES") == 0 )
EXEC SQL UPDATE EMPLOYEE
SET JOB = :newjob
WHERE CURRENT OF C1;

EXEC SQL CLOSE C1;


You can find an example in the SQLLIB\samples\ java\jdbc\dbrsh old.java
May 25 '06 #2

"technocrat " <su************ @gmail.com> wrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...
HOW CAN THIS BE DONE IN JAVA??? THIS IS POSITIONED UPDATE
EXEC SQL DECLARE C1 CURSOR FOR
SELECT *
FROM EMPLOYEE
FOR UPDATE OF JOB;

EXEC SQL OPEN C1;

EXEC SQL FETCH C1 INTO ... ;
if ( strcmp (change, "YES") == 0 )
EXEC SQL UPDATE EMPLOYEE
SET JOB = :newjob
WHERE CURRENT OF C1;

EXEC SQL CLOSE C1;


Here's an example of a positioned update from one of my Java prototypes. It
uses Statements and I'd probably use PreparedStateme nts if I were writing it
today but this will work:

---------------------------------------------------------------------------------------------------------------------
/**
* Do a positioned update in the demonstration table.
*/
public void positionedUpdat e() {

String METHOD_NAME = "positionedUpda te()";

String queryTableSQL = "select lastname, workdept, salary, bonus " +
"from " + demoTable
+ " " + "where workdept = 'D21' " + "for update";
String positionedUpdat eSQL = null;
String newSalary = "50000.00";
BigDecimal minimumBonus = new BigDecimal(450. 00);

/*
* The query will display the rows that will be changed by the
update.
* The update will set all the salaries for those rows to a single
* arbitrary amount but only where the bonus is above an arbitrary
* amount.
*/
Statement queryTableStmt = null;
Statement positionedUpdat eStmt = null;
ResultSet rs01 = null;
try {
queryTableStmt = conn01.createSt atement();
positionedUpdat eStmt = conn01.createSt atement();
rs01 = queryTableStmt. executeQuery(qu eryTableSQL);
String cursorName = rs01.getCursorN ame();
positionedUpdat eSQL = "update " + demoTable + " " + "set salary
= " + newSalary + " "
+ "where current of " + cursorName;
} catch (SQLException excp) {
System.err.prin tln(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while trying to get
information from "
+ demoTable + " table. Error: " + excp);
excp.printStack Trace();
System.exit(16) ;
}

System.out.prin tln("Values before positioned update:");
String spaces = " ";

/* Initialize the host variables used for handling the result set.
*/
String lastname = null;
String workdept = null;
BigDecimal salary = null;
BigDecimal bonus = null;

/*
* Print each line of the result set.
*/
try {
while (rs01.next()) {
lastname = rs01.getString( 1);
workdept = rs01.getString( 2);
salary = rs01.getBigDeci mal(3);
bonus = rs01.getBigDeci mal(4);
System.out.prin tln(lastname + spaces
+ workdept + spaces
+ salary.toString () + spaces
+ bonus.toString( ));
if (bonus.compareT o(minimumBonus) > 0) { //if individual's
// bonus is greater
// than minimum
bonus
positionedUpdat eStmt.executeUp date(positioned UpdateSQL);
//do

// update
}
}
} catch (SQLException sql_excp) {
System.err.prin tln(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while reading " +
demoTable
+ " table. Error: " + sql_excp);
sql_excp.printS tackTrace();
System.exit(16) ;
}

/* Close the result set, dispose of the statements, and commit. */
try {
rs01.close();
queryTableStmt. close();
positionedUpdat eStmt.close();
conn01.commit() ;
} catch (SQLException sql_excp) {
System.err.prin tln(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while closing " +
demoTable
+ " result set, closing statements, or committing.
Error: " + sql_excp);
sql_excp.printS tackTrace();
System.exit(16) ;
}
}

---------------------------------------------------------------------------------------------------------------------

--
Rhino
May 25 '06 #3

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

Similar topics

1
1910
by: | last post by:
Hi All, I have designed a debit-system database with a PHP frontend. The amounts need to be updated on a monthly basis. now i have 10 clients in the system. i can get all the fields and display them, but next to that, i need to insert a field where we can enter an amount per client and after all the new amounts have been filled in, i need to update the database with those amounts entered. I know that by using html forms to enter the...
6
7387
by: Randell D. | last post by:
Folks, I know javascript has no local or server based access to the disk however I was wondering if one can read a remote page and take its html <TITLE> value... My guess is no but thought I'd check/ask anyway... Thanks, randelld
2
2494
by: Igor Shevchenko | last post by:
Hi. I've got a problem with using cursor in a plpgsql function. Cursor is created via DECLARE, it's SELECT query has placeholders. I use PostgreSQL 7.4.2. Here's a problematic plpgsql function: create or replace function add_messages_to_folder(integer,refcursor) returns integer security definer as '
9
11074
by: Acupuncture | last post by:
Hi, I am developing a JDBC application and I encountered this problem (DB2 for ISeries). I want to do a select for update and also use the fetch first rows clause. This is my sql statement: SELECT UsrNbr, UsrPwd, UsrPwdChgD, UsrEmail, UsrChgUsrI, UsrChgDte FROM USERS WHERE UsrNbr = ? FETCH FIRST 1 ROWS ONLY FOR UPDATE This runs fine (the cursor gets this name 'P00022'), but when I execute the
5
1839
by: cdtsly | last post by:
Hi i have a table with all value at 4 i select all lines in a fetch i update one with a value of 7 i update all the row in the fetch with a value 5 the result is that all my row are at 5 and the only line which should be at 7 is at 5 too. i see that the problem is at the first mysql_db_query, and i don t know
0
1282
by: p655279 | last post by:
I read my DB2 manual for positioned update (update .... current of) it says for positioned update: You cannot use an UPDATE statement to modify the rows of a created temporary table. However, you can use an UPDATE statement to modify the rows of a declared temporary table. so what does it mean? what is created temporary table and what is declared temporary table? Anyone knows?
2
4963
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I've a xml svg file and I would like to update it with Python. First, I would like to fetch one dom node with getElementByID. I've one issue about this method. This is my example : My SVG file :
1
4632
by: shorti | last post by:
I am on DB2 UDB V8.2 When I try to do a simple update with a "Fetch First" clause I get a syntax error: db2 "update exec_1 set lock = 100, level = 50 where level = 0 fetch first 100 rows only" DB21034E The command was processed as an SQL statement because it was not a
10
7405
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark extender to TextBox. Inside a Update panel i have Lable.. and the update panel refreshes each 3 seconds and it fetches data and displays it. But my problem is whenever the data is fetched from Server the textbox watermark flickers. i dont know why it...
0
8347
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
8275
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
8694
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
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,...
0
8571
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
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...
1
6157
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
4143
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...
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.