2009-12-16 6 views
0

SQL 서버 (200) 자바 1.4 보스 3java : java 1.4 api에서 값이 false 인 자동 커밋 모드를 설정할 수 없습니까?

HI는

코드가

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; 

      } 

이의 원인이 무엇 이하 "관리 트랜잭션 동안 당신은 설정할 수 없습니다 자동 커밋"예외 메시지 무엇입니까 예외는 무엇을 의미합니까?

답변

1

오류는 분명합니다. 관리 트랜잭션 중에 자동 커밋을 설정할 수 없습니다. 이것이 기본값이기 때문에 이것을 false로 설정할 필요조차하지 않아야한다. 자동 커밋을 가능하게하기 위해 사용한다.

J2EE 및 EJB를 사용하고 있고 자동 커밋을 활성화하려는 경우 BMT (bean managed transaction)로 설정을 변경할 수 있으며이 설정을 사용하면이 설정을 수정할 수 있습니다.

그러나 코드에서 사용하는 방식을 false로 설정할 필요는 없으며 모든 것이 트랜잭션에서 수행되고 커밋 또는 롤백으로 제어합니다.