rollback执行了,但数据库数据却不对,WHY?(100分)

  • 主题发起人 主题发起人 usa112233
  • 开始时间 开始时间
U

usa112233

Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下:
try{
myPool = DBConnectionPool.getInstance(req.getDBName());
myConn = myPool.getConnection();
myConn.setAutoCommit(false);

FileInputStream testFile = new FileInputStream(fileName);
BufferedReader br = new BufferedReader (new InputStreamReader(testFile));
String line = null;
String[] sa ;
AccountDetail1 ad1 = new AccountDetail1();
while (( line = br.readLine()) != null){
System.out.println(line);
sa = line.split(",");
processedCount++;
ad1.clear();
ad1.setField(AccountDetail1.FLD_ACCOUNTNO,sa[0]);
ad1.setField(AccountDetail1.FLD_DATE,sa[1]);
ad1.setField(AccountDetail1.FLD_NOTENO,sa[2]);
ad1.setField(AccountDetail1.FLD_AMOUNT,sa[3]);
ad1.setField(AccountDetail1.FLD_CREDITORDEBIT,sa[4]);
ad1.setField(AccountDetail1.FLD_DESCRIPT,sa[5]);
ad1.setField(AccountDetail1.FLD_BALANCE,sa[6]);
ad1.setField(AccountDetail1.FLD_STATUS,"0");
ad1.add();
}
br.close();
Output ProcessedCountOutput = new Output();
ProcessedCountOutput.setName("ProcessedCount");
ProcessedCountOutput.setContent("共装载"+processedCount+"条记录");
res.addOutput(ProcessedCountOutput);
myConn.commit();
}catch (Exception e1){
try {
if (myConn != null){
System.out.println("rollback");
myConn.rollback();
}
}catch (DBException de){
System.out.println("事务处理错误");
}
Output ProcessErrorOutput = new Output();
ProcessErrorOutput.setName("ProcessError");
ProcessErrorOutput.setContent("数据装载错,请联系系统管理员");
res.addOutput(ProcessErrorOutput);

System.out.println("err");
}
数据库出错时,应rollback,语句myConn.rollback();也执行了,但数据库里的记录还是被修改了,好象该语句没执行成功。
我用的是INFORMIX
 
你好象没有启动事务
 
怎样启动事务?
 
没有启动事务
var
TD: TTransactionDesc;
begin
TD.TransactionID := 1;
TD.IsolationLevel := xilREADCOMMITTED;
myConn.StartTransaction(TD);
try
........
SQLConnection1.Commit(TD);
{on success, commit the changes};
except
SQLConnection1.Rollback(TD);
{on failure, undo the changes};
end;
end;


end;

 
是JAVA,不是DELPHI
 

Similar threads

后退
顶部