sql语句:
 begin
 savepoint ps;
  merge into 1;
  merge into 2;
  merge into 3;
  merge into 4;
....
  commit;
exception
  when others then
    rollback to ps;
end;
后台:
    try {
        String strSql =“sql”;
      con = DataSource.getDataSource();
        ps = con.prepareStatement(strSql);
        int result = ps.executeUpdate();      }
      catch (Exception e) {
         throw e;
      }
希望在页面显示捕获的异常,求解。

解决方案 »

  1.   

    在sql里这样写exception
      when others then
    begin
      rollback to ps;
    raise;
    end;
    end;里面的RAISE也可以自己定义错误信息,不过一般用ORACLE的错误信息就好了
      

  2.   

    我看到有人在 rollback前这么写
        DBMS_OUTPUT.put_line('异常编号 : ' || sqlcode);
        DBMS_OUTPUT.put_line('异常的详细信息 : ' || substr(sqlerrm, 1, 100));
    但是我试了下不行,
    还有就是我如果想确定是哪一个哪一句报异常,怎么在每个merge后面定义raise
      

  3.   

    exception
      when others then
    begin
      rollback to ps;
    raise;
    end;
    end;