2009-12-16 47 views
0

SQL服务器200 的Java 1.4 JBoss的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,如果您是并且您希望启用自动提交,则可以将您的设置更改为Bean管理事务(BMT),这将允许您修改此设置。

但是,您在代码中使用它的方式不需要将其设置为false,所有操作都在事务中完成,并且您可以使用commit或rollback来控制它们。

相关问题