2015-10-09 269 views
2

調用java我有以下代碼(我試圖做的是從調用PLSQL Java代碼在google.com打開一個新的網頁):我似乎無法從PLSQL

  CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Hello" AS 
      import java.awt.Desktop; 
      import java.net.URI; 
      class Hello 
      { 
      public static void main(String args[]) throws Exception 
      { 
      Desktop d=Desktop.getDesktop(); 
      d.browse(new URI("http://google.com")); 
      } 
      }; 
      /

     CREATE OR REPLACE PROCEDURE SAMP_JAVA_CALL AS 
     LANGUAGE JAVA NAME 'Hello.main(java.lang.String[])'; 
     /

它編譯沒有任何錯誤,但是當我嘗試執行SAMP_JAVA_CALL過程中,我得到這個錯誤:

Error report - 
    ORA-29549: class JAYPV.Hello has changed, Java session state cleared 
    ORA-06512: at "JAYPV.SAMP_JAVA_CALL", line 1 
    ORA-06512: at line 1 
    29549. 00000 - "class %s.%s has changed, Java session state cleared" 
    *Cause: A class in use by the current session was redefined or dropped, 
      invalidating the current Java session state and requiring that 
      it be cleared. 
    *Action: No action required. 

你有這是爲什麼不工作的任何想法? 我正在使用sqldeveloper版本4.0.0.13,Oracle版本12c。

+0

提到遵循這一https://docs.oracle。 com/cd/B19306_01/java.102/b14187/chthree.htm –

回答

1
ORA-29549: class ... has changed, Java session state cleared 

Cause: A class in use by the current session was redefined or dropped, invalidating the current Java session state and requiring that it be cleared.

「正常」方式,就可能出現這個錯誤是編譯Java對象在數據庫中並在同一個會話執行它。基本上當你改變java對象這會發生。 如果再次調用它,它將成功執行,結束會話,創建新會話也將起作用。

但是你可以使用一個技巧,我發現here。你可以發出在異常處理程序DBMS_JAVA.ENDSESSION_AND_RELATED_STATE來解決它,就像下面

DECLARE 
JAVA_SESSION_CLEARED EXCEPTION; 
PRAGMA EXCEPTION_INIT(JAVA_SESSION_CLEARED, -29549); 
-- 
V_KEEP_TRIES NUMBER := 3; 
V_TMP VARCHAR2(32000); 
BEGIN 
<<BEFORE_JAVA_CALL>> 
BEGIN 

JAVA_WRAPPER_PROC; 

EXCEPTION 
WHEN JAVA_SESSION_CLEARED THEN 
V_TMP := DBMS_JAVA.ENDSESSION_AND_RELATED_STATE; 
V_KEEP_TRIES := V_KEEP_TRIES - 1; 
IF V_KEEP_TRIES >= 0 THEN 
GOTO BEFORE_JAVA_CALL; 
ELSE 
RAISE; 
END IF; 
WHEN OTHERS THEN 
LM.SET_STATUS('FAILED', SQLERRM); 
RAISE; 
END; 
+0

我已將'JAVA_WRAPPER_PROC'更改爲我的過程的名稱,但它仍然不起作用。我現在得到這個錯誤:'..identifier'SET_STATUS'必須聲明...'。我應該怎麼做@UUIIUI? – Vance

+0

@Vance我不確定,可能是**特權相關的問題**。程序或程序包的所有者必須已被明確授予對代碼正文中引用的所有對象的必要對象特權。Plz檢查特權。 – Bikku