PreparedStatement executeBatch run after an exception
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   doron_ben
Posted On:   Tuesday, October 11, 2011 06:44 AM

I am using batch insert using PreparedStatement and when a SQLException (that is ok the data is fail on a constrain ) thrown the next time i enter the function the executeBatch on the new data enter all the data from the fail exception that on the ok PreparedStatement for example : if in the fail migration list of 100 items the sql exseption throws i close the PreparedStatements then catch the exception in an upper level out of the function now send 1 new item in a list to the function the second PreparedStatement that the data in it was ok run even that the function got only 1 item in the DB i will get on the second items 101 in the table this is my code : @Res   More>>

I am using batch insert using PreparedStatement and when a SQLException (that is ok the data is fail on a constrain ) thrown the next time i enter the function the executeBatch on the new data enter all the data from the fail exception that on the ok PreparedStatement
for example :

if in the fail migration list of 100 items the sql exseption throws
i close the PreparedStatements then catch the exception in an upper level out of the function now send 1 new item in a list to the function the second PreparedStatement that the data in it was ok run even that the function got only 1 item in the DB i will get on the second items 101 in the table



this is my code :







@Resource

protected SessionContext sctx;

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

public void batchInsertMigration(Collection migrationList) throws SQLException {

Connection conn = ((Session) getEntityManager().getDelegate()).connection();

PreparedStatement vendorPs = null;

PreparedStatement vendorAccountPs = null;

.

.

.

String str = getInsertStr(tableName);

vendorPs = conn.prepareStatement(str);

.

.

.


str = getInsertStr(tableName);

vendorAccountPs = conn.prepareStatement(str);




.

.

.

setParametersToVendor(vendorPs, migrationList.getVendor());

vendorPs.addBatch();

.

.

.

setParametersToVendorAccount(vendorAccountPs ,migrationList.getVendorAccount());

vendorAccountPs.addBatch();



this is where the exception thrown --->vendorPs.executeBatch();

---> in the next run this table get the old items vendorAccountPs.executeBatch();



} catch (SQLException e) {

sctx.setRollbackOnly();

throw e;

} finally {

try {

closePS(vendorPs);

closePS(vendorAccountPs);

}

catch (SQLException e) {

}





PLEASE HELP
Thanks    <<Less
About | Sitemap | Contact