请问如何得到Oracle SQLException的errorCode, 用SQLException.getErrorcode() 总是返回0例如有如下Oracle Exception:
org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
pacwas1:1521:testdb
); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
xxx:1521:xxx
))当Catch到这个SQLException并且使用getErrorcode() 总是返回0,但我期待的是ORA-12505,请问有好的方法吗?

解决方案 »

  1.   

    create type t_oracle_error is object ( 
    error_num varchar2(9), 
    error_desc varchar2(1024) 
    ); 
    create type t_oracle_error_tab is table of t_oracle_error; create or replace function OracleErrors return t_oracle_error_tab pipelined is 
      l_error t_oracle_error := t_oracle_error(null,null); 
    begin 
      for errNo in reverse -32799..0 loop 
        l_error.error_num := errNo; 
        l_error.error_desc := sqlerrm(errNo); 
        if l_error.error_desc not like '%Message % not found;%' and l_error.error_desc != 'ORA'||to_char(errNo,'FM09999')||': ' then 
          pipe row(l_error); 
        end if; 
      end loop; 
      return; 
    end OracleErrors; select * from table(oracleerrors); 
      

  2.   

    我只的是在JAVA里如何得到SQLException的error code