473,378 Members | 1,475 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,378 software developers and data experts.

DB2Driver; rollback closing resultsets

Hello

While testing our code on DB2 we have encountered a difference in the
behaviour of DB2Driver (com.ibm.db2.jcc.DB2Driver with driverType= 4)
compared to the drivers offered by Oracle 9i and Sybase SQL Anywhere 7.

Our system contains code like this (java pseudocode)

Connection con = <>
con.setAutoCommit(false);
PreparedStatement psel = con.prepareStatement(<select from table A
where...>);
...
ResultSet res = psel.executeQuery();
while (res.next())
{
boolean success = <Perform various inserts and updates in other tables
than table A>;
if (success)
con..commit();
else
con..rollback():
}
...
try{con.setAutoCommit(true);}catch (Exception err){}
The purpose of this structure is to catch and rollback errors, but also to
keep processing the remaining lines from the resultset.
This works fine in both Oracle and Sybase. But in DB2 a rollback call causes
the resultset to close.

Why does this happen ? is this behaviour a bug in the DB2Driver ? has it
been fixed ?

We need to decide our next step here, If we can't get DB2Driver to behave
the way we expect,
we have to consider looking at alternative drivers or rewriting out code
(which will be unplesant).

Comments are welcome.

Tor
Nov 12 '05 #1
6 4810
Ian
Tor Heigre wrote:
Hello

While testing our code on DB2 we have encountered a difference in the
behaviour of DB2Driver (com.ibm.db2.jcc.DB2Driver with driverType= 4)
compared to the drivers offered by Oracle 9i and Sybase SQL Anywhere 7.

Our system contains code like this (java pseudocode)

Connection con = <>
con.setAutoCommit(false);
PreparedStatement psel = con.prepareStatement(<select from table A
where...>);
...
ResultSet res = psel.executeQuery();
while (res.next())
{
boolean success = <Perform various inserts and updates in other tables
than table A>;
if (success)
con..commit();
else
con..rollback():
}
...
try{con.setAutoCommit(true);}catch (Exception err){}
The purpose of this structure is to catch and rollback errors, but also to
keep processing the remaining lines from the resultset.
This works fine in both Oracle and Sybase. But in DB2 a rollback call causes
the resultset to close.

Why does this happen ? is this behaviour a bug in the DB2Driver ? has it
been fixed ?

We need to decide our next step here, If we can't get DB2Driver to behave
the way we expect,
we have to consider looking at alternative drivers or rewriting out code
(which will be unplesant).


This is language independent. I have run into this using perl, and I was
able to work around it by opening 2 separate connections to the database.
Example,

Connection con1 = <> // for reading only
Connection con2 = <> // for your actual transactions
con2.setAutoCommit(false);
PreparedStatement psel = con1.prepareStatement(<select from table A
where...>);
....
ResultSet res = psel.executeQuery();
while (res.next())
{
boolean success = <Perform various inserts and updates in other tables
than table A>;
if (success)
con2..commit();
else
con2..rollback():
}
....
try{con2.setAutoCommit(true);}catch (Exception err){}

I can't speak to why this is different between the DB2/Oracle/Sybase
implementation. If this workaround is not sufficient you might want to
open a PMR with IBM.
Good luck,

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #2
A result set is part of the calling statements unit of work. Rollback
will always close all cursors for the application (including result sets).

Tor Heigre wrote:
Hello

While testing our code on DB2 we have encountered a difference in the
behaviour of DB2Driver (com.ibm.db2.jcc.DB2Driver with driverType= 4)
compared to the drivers offered by Oracle 9i and Sybase SQL Anywhere 7.

Our system contains code like this (java pseudocode)

Connection con = <>
con.setAutoCommit(false);
PreparedStatement psel = con.prepareStatement(<select from table A
where...>);
..
ResultSet res = psel.executeQuery();
while (res.next())
{
boolean success = <Perform various inserts and updates in other tables
than table A>;
if (success)
con..commit();
else
con..rollback():
}
..
try{con.setAutoCommit(true);}catch (Exception err){}
The purpose of this structure is to catch and rollback errors, but also to
keep processing the remaining lines from the resultset.
This works fine in both Oracle and Sybase. But in DB2 a rollback call causes
the resultset to close.

Why does this happen ? is this behaviour a bug in the DB2Driver ? has it
been fixed ?

We need to decide our next step here, If we can't get DB2Driver to behave
the way we expect,
we have to consider looking at alternative drivers or rewriting out code
(which will be unplesant).

Comments are welcome.

Tor


Nov 12 '05 #3
"Sean McKeough" <mc******@nospam.ca.ibm.com> wrote in message
news:bq**********@hanover.torolab.ibm.com...
A result set is part of the calling statements unit of work. Rollback
will always close all cursors for the application (including result sets).

I don't know about "result sets" but a declared cursor can be held open past
the commit/rollback using the WITH HOLD option.
Nov 12 '05 #4
May be the following IBM doc link will help you (holdability section).
http://publib.boulder.ibm.com/infoce...d/cjvrsush.htm

In short: in db2 there are 2 types of the cursors, "with hold" cursors
should cross the transaction bounadries.

We do use "with hold" in SQL stored procedures, but JDBC stored
procedures seem to work fine without any "holdability" modifications
(7.2 fixpack 6 and 8.1 fixpack 3).

regards,
dmitri
Nov 12 '05 #5
With hold will keep the cursor open through a commit, but not a rollback.

More details...
WITH HOLD
Maintains resources across multiple units of work. The effect of
the WITH HOLD cursor attribute is as follows:

*****Forr units of work ending with COMMIT:
o Open cursors defined WITH HOLD remain open. The cursor
is positioned before the next logical row of the results table.

If a DISCONNECT statement is issued after a COMMIT
statement for a connection with WITH HOLD cursors, the held cursors must
be explicitly closed or the connection will be assumed to have performed
work (simply by having open WITH HELD cursors even though no SQL
statements were issued) and the DISCONNECT statement will fail.
o All locks are released, except locks protecting the
current cursor position of open WITH HOLD cursors. The locks held
include the locks on the table, and for parallel environments, the locks
on rows where the cursors are currently positioned. Locks on packages
and dynamic SQL sections (if any) are held.
o Valid operations on cursors defined WITH HOLD
immediately following a COMMIT request are:
+ FETCH: Fetches the next row of the cursor.
+ CLOSE: Closes the cursor.
o UPDATE and DELETE CURRENT OF CURSOR are valid only for
rows that are fetched within the same unit of work.
o LOB locators are freed.
******** For units of work ending with ROLLBACK:
o All open cursors are closed.
o All locks acquired during the unit of work are released.
o LOB locators are freed.
Mark A wrote:
"Sean McKeough" <mc******@nospam.ca.ibm.com> wrote in message
news:bq**********@hanover.torolab.ibm.com...
A result set is part of the calling statements unit of work. Rollback
will always close all cursors for the application (including result
sets).


I don't know about "result sets" but a declared cursor can be held
open past
the commit/rollback using the WITH HOLD option.


Nov 12 '05 #6
With hold will keep the cursor open through a commit, but not a rollback.

Mark A wrote:
"Sean McKeough" <mc******@nospam.ca.ibm.com> wrote in message
news:bq**********@hanover.torolab.ibm.com...
A result set is part of the calling statements unit of work. Rollback
will always close all cursors for the application (including result sets).


I don't know about "result sets" but a declared cursor can be held open past
the commit/rollback using the WITH HOLD option.


Nov 12 '05 #7

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

Similar topics

1
by: Jung | last post by:
I am trying to make connection to Content Manager. Can anyone help me how to fix this error? Thank you. Exception in thread "main" java.lang.UnsatisfiedLinkError: SQLAllocEnv at...
0
by: Crazy Cat | last post by:
Hi, Using Visual Basic 2005 -- I have a stored procedure that returns multiple resultsets. I fill a datareader (SQLDataReader to be exact) with the results from a command object's ExecuteReader...
5
by: praveen | last post by:
Hi, I am using nested resultsets to execute queries on two different tables. The code structure is: stmt1 = conn.createStatement(); rs1 = stmt1.executeQuery(query1); while (rs1.next()) {...
1
by: spriyasenthil | last post by:
How to Rollback between two different DB in ORACLE? -------------------------------------------------------------------------------- Hi all! Am using two different DB in ORACLE! Letz take it...
2
by: Hans Horn | last post by:
Folks, I just upgraded to ESE UDBv91 (from v82) and found that there's no COM.ibm.db2.jdbc.net.DB2Driver in db2java.zip anymore. the only one that's there is the COM.ibm.db2.jdbc.app.DB2Driver...
1
by: rpm45tech | last post by:
Hi everyone. I'm deveolping in Java with DB2 running on Win XP and everything was working ok but then I installed Vista Ultimate and the application stopped working. This is the exception showed: ...
2
by: Ian Boyd | last post by:
We're encountering a situation where we're encountering a deadlock, and someone's been made the deadlock victim. But after that, DB2 refuses to run any SQL, and instead we get the error message: ...
6
by: iKiLL | last post by:
Hi all I am developing in C#, CF2 and SQL Mobile. Currently my app is using Merge Replication. This is all working well. I have now decided to try and use Result sets in my application but I...
10
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm using this coding to get 2 resultsets thru datareader and then load them into 2 datatables and bind the datatables to datagridviews. But sdrGrid.NextResult() is returning false for some...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...

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.