Java : Java 1.4 API에서 값으로 자동 커밋 모드를 설정할 수 없습니까?
-
19-09-2019 - |
문제
SQL Server 200 Java 1.4 Jboss 3
안녕하세요 예외 메시지를 받고 있습니다. "관리되는 거래 중에 자동 커밋을 설정할 수 없습니다"
코드는 다음과 같습니다
try {
try {
connection = getConnection();
} catch (Exception e) {
throw new ConnectionException(e.getMessage());
}
for(int i=0;i<recordIds.size();i++)
{
String currentRecordId=(String)recordIds.get(i);
try
{
//exception on this line connection.setAutoCommit(false);
preparedStatement = connection.prepareStatement(getSQL("PurgeRecordInDumpData"));
preparedStatement.setLong(1,Long.parseLong(currentRecordId));
int numberOfUpdates=preparedStatement.executeUpdate();
if(numberOfUpdates!=1)
{
throw new Exception("Record with record id "+currentRecordId +"could not be purged.");
}
preparedStatement.close();
connection.commit();
listOfPurgedRecords.add(currentRecordId);
}
catch(Exception e)
{
connection.rollback();
}
}
return listOfPurgedRecords;
}
이 예외의 원인은 무엇이며 무엇을 의미합니까?
해결책
오류는 분명합니다. 관리 거래중인 동안 자동 커밋을 설정할 수 없습니다. 기본값이므로이를 False로 설정할 필요조차 없습니다. 자동 커미트를 활성화하는 데 사용합니다.
J2EE 및 EJB를 사용하는지 확실하지 않습니다. 귀하가 있고 AutoCommit을 활성화하려면 설정을 BEAN 관리 트랜잭션 (BMT)으로 변경할 수 있으므로이 설정을 수정할 수 있습니다.
그러나 코드에서 사용하는 방식은 허위로 설정할 필요가 없으며 모든 것이 트랜잭션에서 수행되며 커밋 또는 롤백으로 제어합니다.
제휴하지 않습니다 StackOverflow