【发布时间】:2009-12-16 06:49:59
【问题描述】:
sql 服务器 200 爪哇 1.4 老板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;
}
这个异常的原因是什么?它是什么意思?
【问题讨论】:
标签: sql-server transactions rollback java1.4 autocommit