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

DB2 Express UDB 9 with db2jcc JDBC driver- Issues with Auto generatedfield

Hi All,
We are testing one of our component with JDBC + DB2 using db2jcc
driver. We afced a strange issue.
Scenario is like this.
1. We insert 1 record to a table having IDENTITY column as the primary
key and retrieve the newly inserted identity value using
getGeneratedKeys() API of JDBC 3.0. It works fine
2. Immediate after that we insert a record into another table which is
having no identity column. But after insert if I call
getGeneratedKeys(), it is returning me a valid ResultSet and if get
the value, it is returning the identity value of the first insert.

Why it is happening like that? This creates trouble as the client
application keeps on inserting records , some to tables having
IDENTITY column and some to tables without IDENTITY. But once an
insert to tables having IDENTITY happens, all other insert to tables
without identity returns theat idenity value.

We earlier tested MS SQL server 2005 , Oracle 10g and MySQL 5. All
worked fine.

This is the sample code.
{
String sql = "INSERT INTO TEST_TABLE_AUTOID(COL2, COL3) values(?,?)";
ResultSet rs = null;

PreparedStatement stmt = connection1.prepareStatement(sql,
PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, "Test11");
stmt.setString(2, "Test11");
int ret = stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
if(rs != null) {
while(rs.next()) {
System.out.println("Inside ");
String data = rs.getString(1);
// Get automatically generated key
// values
System.out.println("automatically generated key value = " +
data);

}
}
rs.close();
stmt.close();
connection1.commit();
}

{
String sql = "INSERT INTO TEST_TABLE(COL1, COL2)
values(?,?)";
ResultSet rs = null;

PreparedStatement stmt = connection1.prepareStatement(sql,
PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setInt(1, 14);
stmt.setString(2, "Test14");
int ret = stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
if(rs != null) {
while(rs.next()) {
System.out.println("Inside");
java.math.BigDecimal idColVar = rs.getBigDecimal(1);
//String data = rs.getString(1);
// Get automatically generated key
// values
System.out.println("automatically generated key value = " +
idColVar);

}
}
rs.close();
stmt.close();
connection1.commit();
}
Jul 14 '08 #1
2 3515
Hi. It's clearly a driver bug. The driver should nullify any of a
statement's values related to an execution
when the statement is re-executed.
Joe Weinstein at Oracle
Jul 14 '08 #2
jo*******@bea.com wrote:
Hi. It's clearly a driver bug. The driver should nullify any of a
statement's values related to an execution
when the statement is re-executed.
Yes, I have discussed with the JCC team and it's a known issue.
If you want to ensure it's fixed in a timely fashion probably best to
open a PMR, so you can track when/that it's done.
Joe Weinstein at Oracle
Are you the one (ex-BEA) who survived?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 14 '08 #3

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

Similar topics

1
by: Axel Dachtler | last post by:
Hello, my Java-program can't load the JDBC driver. I always get a java.lang.NoClassDefFoundError when I run it. The JDBC Driver is in the directory: C:\programs\ora92\jdbc\lib I think I...
3
by: Steverino | last post by:
Hi, I'm currently trying to learn DB2. I have the following version below installed on my server machine on my little LAN. However when I try to connect to it from my client machine, I receive...
4
by: Dani | last post by:
Hi everyone Description of the problem: Using a PreparedStatement to write down an integer (int) plus a timestamp for testing purposes. When read out again the integer looks very different. We...
0
by: xixi | last post by:
hi, i am trying to do java -cp "C:\program files\ibm\sqllib\java\db2jcc.jar" com.ibm.db2.jcc.DB2Binder -url jdbc:db2://xxx:xxx/xx -user xx -password xx -size 80 under db2 command window, i have...
2
by: Raquel | last post by:
Read this about the Universal JDBC Driver.... "In a Type 2 mode, the Universal JDBC driver provides local application performance gains (because it avoids using TCP/IP protocol to communicate to...
1
by: rafikki3 | last post by:
I have a java web application that is using the db2jcc driver to get a connection to a DB2 database that is located on an RS 6000 server. The here is a portion of the code that is giving me a...
1
by: db2group88 | last post by:
Hi, we are using db2 ESE v8.2.3 on windows, i try to use command window to do binding D:\Program Files\IBM\SQLLIB\bnd>java -cp "D:\program files\ibm\sqllib \java\db2jcc.jar"...
0
by: Bonna | last post by:
Hi there, A small challenge for all you 'DB2 Gurus' out there !!! I downloaded DB2 Express-C for XP Home from the following site : ...
1
by: chihfei.lai | last post by:
Hi all, As title!! My development environment is db2 v8.1. But my production environment is db2 v7.2. Can I use db2jcc.jar to connect to db2 v7.2? Thanks a lot. Chih-Fei.
1
by: gimme_this_gimme_that | last post by:
Hello fellow DB2ers! I have a new DB2 Express-C (version 9.5) installation running on Vista Business. I'm able to create new databases using the "create db dbname" command. I'm setting...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.