Reputation: 897
I have the following codes(what I am trying to do is to open a new web page in google.com by calling java code through 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[])';
/
and it compiles without any errors but when I try to execute the SAMP_JAVA_CALL
procedure, I am getting this error:
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.
Do you have any idea why this is not working? I am using sqldeveloper Version 4.0.0.13, Oracle version 12c.
Upvotes: 2
Views: 633
Reputation: 8616
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.
The "normal" way this error can occur is to compile a java object in the database and execute it in the same session. Basically when you alter the java object this will happen. If you call it again, it will execute successfully, ending the session, creating a new session will also work.
But you can use one trick which I found here.You can Issue a DBMS_JAVA.ENDSESSION_AND_RELATED_STATE
in the exception handler to resolve it just like mentioned in below
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;
Upvotes: 1