Hi Friends,
I am facing a database deadlock problem while inserting data using SingleConnectiondatasource. I am not sure what is the actual cause for this.Please find my below code snippet .
Java Code
try{
SingleConnectionDataSource scds = null;
JdbcTemplate sdscJdbcTemplate = null;
scds = new SingleConnectionDataSource(getDataSource().getConn ection(), true);
scds.getConnection().setAutoCommit(false);
sdscJdbcTemplate = getSingleConnectionJdbcTemplate(scds);
noOfRowsReturned = sdscJdbcTemplate.batchUpdate(updatePersonDetails, new BatchPreparedStatementSetter() {
@Override
public void setValues(
PreparedStatement ps, int i)
throws SQLException {
ps.setInt(1, existingIds.get(i));
ps.setInt(2, empId);
ps.setInt(3, processId);
ps.setString(4, createdBy);
}
@Override
public int getBatchSize() {
logger.info("Records Updated");
return existingIds.size();
}
});
scds.getConnection().commit();
} catch (DataAccessException dae) {
try {
scds.getConnection().rollback();
} catch (SQLException e) {
logger.error("SQLException : " + e.getMessage(), e);
}
logger.error("DataAccessException : " + dae.getMessage(), dae);
throw new CamsDaoException(dae.getMessage(), CamsErrorType.DB_ERROR);
} finally {
scds.destroy();
logger.debug(LogUtil.MSG_END);
}
Thanks in Advance
Siva
I am facing a database deadlock problem while inserting data using SingleConnectiondatasource. I am not sure what is the actual cause for this.Please find my below code snippet .
Java Code
try{
SingleConnectionDataSource scds = null;
JdbcTemplate sdscJdbcTemplate = null;
scds = new SingleConnectionDataSource(getDataSource().getConn ection(), true);
scds.getConnection().setAutoCommit(false);
sdscJdbcTemplate = getSingleConnectionJdbcTemplate(scds);
noOfRowsReturned = sdscJdbcTemplate.batchUpdate(updatePersonDetails, new BatchPreparedStatementSetter() {
@Override
public void setValues(
PreparedStatement ps, int i)
throws SQLException {
ps.setInt(1, existingIds.get(i));
ps.setInt(2, empId);
ps.setInt(3, processId);
ps.setString(4, createdBy);
}
@Override
public int getBatchSize() {
logger.info("Records Updated");
return existingIds.size();
}
});
scds.getConnection().commit();
} catch (DataAccessException dae) {
try {
scds.getConnection().rollback();
} catch (SQLException e) {
logger.error("SQLException : " + e.getMessage(), e);
}
logger.error("DataAccessException : " + dae.getMessage(), dae);
throw new CamsDaoException(dae.getMessage(), CamsErrorType.DB_ERROR);
} finally {
scds.destroy();
logger.debug(LogUtil.MSG_END);
}
Thanks in Advance
Siva