This is a discussion on prepared statement not returning keys; driver used(mysql-connector-java-3.1.14-bin.jar) within the MySQL Database forums, part of the Database Forums category; getGeneratedKeys() method not returning resultset containing keys after executing prepared statements in a batch The code snippet is given below ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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); } |