Unix Technical Forum

prepared statement not returning keys; driver used(mysql-connector-java-3.1.14-bin.jar)

This is a discussion on prepared statement not returning keys; driver used(mysql-connector-java-3.1.14-bin.jar) within the MySQL forums, part of the Database Server Software category; --> getGeneratedKeys() method not returning resultset containing keys after executing prepared statements in a batch The code snippet is given ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:24 AM
dsm100@gmail.com
 
Posts: n/a
Default prepared statement not returning keys; driver used(mysql-connector-java-3.1.14-bin.jar)

getGeneratedKeys() method not returning resultset containing keys
after executing prepared statements in a batch

The code snippet is given below

String insertQuery = "INSERT INTO PRICE_LIST(ID,
SKU_CODE)VALUES(?,?)";

connection = springDataSource.getConnection();
preparedStatement = connection.prepareStatement(insertQuery);
for (int listPriceCount = 0; listPriceCount < listPrices.length;
listPriceCount++) {

preparedStatement.setInt(1, listPrices[listPriceCount]
.getID());
preparedStatement.setInt)2, listPrices[listPriceCount]
.getName());

preparedStatement.addBatch();
}

preparedStatement.executeBatch();

keySet = preparedStatement.getGeneratedKeys();

for (int listPriceCount = 0; keySet.next(); listPriceCount++) {
int key = keySet.getInt(1);
listPrices[listPriceCount].setId(key);
logger.debug("generated key: " + key);
}

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com