Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > DB2 Express UDB...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9086 of 9520
Post > Topic >>

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

by Zunil <zunilp@[EMAIL PROTECTED] > Jul 14, 2008 at 06:15 AM

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();
	        }
 




 3 Posts in Topic:
DB2 Express UDB 9 with db2jcc JDBC driver- Issues with Auto gene
Zunil <zunilp@[EMAIL P  2008-07-14 06:15:56 
Re: DB2 Express UDB 9 with db2jcc JDBC driver- Issues with Auto
"joeNOSPAM@[EMAIL PR  2008-07-14 07:00:31 
Re: DB2 Express UDB 9 with db2jcc JDBC driver- Issues with Auto
Serge Rielau <srielau@  2008-07-14 15:40:11 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:08:34 CST 2008.