Home » SQL & PL/SQL » SQL & PL/SQL » Problem while accessing java code from oracle
Problem while accessing java code from oracle [message #217175] Wed, 31 January 2007 23:54 Go to next message
agrawal_vaibhao
Messages: 20
Registered: May 2006
Junior Member

Hi,
I am loading Java class to oracle using loadjava utility and accessing Java code through my oracle stored functions.
It works fine when i load single class and calls its methods within oracle stored function.
But the problem is that when that load two or more classes that are dependent on each other, then those classes are loaded in invalid state in oracle.
And so there was problem while access that Java code in oracle.
Can any one help me !
Re: Problem while accessing java code from oracle [message #217187 is a reply to message #217175] Thu, 01 February 2007 01:19 Go to previous messageGo to next message
sdecman
Messages: 20
Registered: July 2005
Location: Ljubljana, Slovenia
Junior Member
There are many things that can go wrong with loading java and by executing java classes as well. Hence, why use java in the first place? But sometimes we just can't go without.

We need some example(s) in order to be of some use. We need to get started somewhere. Are the procedures inside classes public? Are they static? Are classes part of the same package?

Try to compile classes manually:

SDECMAN@O102> SELECT dbms_java.longname(object_name) as class_name,
  2         status
  3    FROM user_objects
  4   WHERE object_type = 'JAVA CLASS'
  5     AND status = 'INVALID';

CLASS_NAME                     STATUS
------------------------------ -------
test1/TestClass2               INVALID


SDECMAN@O102> ALTER JAVA CLASS "test1/TestClass2" COMPILE;

Warning: Java altered with compilation errors.

SDECMAN@O102> show errors
Errors for JAVA CLASS /aab9b48_TestClass2:

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      ORA-29521: referenced name test1/TestClass1 could not be found

If the ERROR isn't explainatory enough, post it and we'll try to go from there.

Cheers
Re: Problem while accessing java code from oracle [message #217204 is a reply to message #217187] Thu, 01 February 2007 03:04 Go to previous messageGo to next message
agrawal_vaibhao
Messages: 20
Registered: May 2006
Junior Member

SQL> Select t.object_name,t.object_type,t.status
2 From User_Objects t
3 where t.object_type in ('JAVA CLASS', 'JAVA RESOURCE');

OBJECT_NAME OBJECT_TYPE STATUS
-------------------------------------------------------------------------------- ------------------- -------
Crypto JAVA CLASS VALID
KeyUtil JAVA CLASS VALID
Stat JAVA CLASS VALID
Hello JAVA CLASS VALID

SQL> set serveroutput on;
SQL>
SQL> Declare
2 v_result Varchar2(100);
3 Begin
4 v_result := encrypt(p_string => 'testing');
5 dbms_output.put_line(v_result);
6 End;
7 /

Declare
v_result Varchar2(100);
Begin
v_result := encrypt(p_string => 'testing');
dbms_output.put_line(v_result);
End;

ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerException
ORA-06512: at "DEMOTEST.ENCRYPT", line 1
ORA-06512: at line 4

Here is what i m getting even though my java souce is in valid state.
This Java Class's method's are working fine from java not giving null pointer exception.
But in oracle it is giving NullPointerException.

So plz help me.
Re: Problem while accessing java code from oracle [message #217212 is a reply to message #217204] Thu, 01 February 2007 03:35 Go to previous messageGo to next message
sdecman
Messages: 20
Registered: July 2005
Location: Ljubljana, Slovenia
Junior Member
Quote:

But the problem is that when that load two or more classes that are dependent on each other, then those classes are loaded in invalid state in oracle.
And so there was problem while access that Java code in oracle.



Your problem is not invalid state of java classes in Oracle then. Your problem is INSIDE the java source - the call returns Java exception. But there is still not enough information to say anything. Tell me, which java class is mapped to your PL/SQL's encrypt function? It would be best to see the source code of the java classes involved but because of the nature of use (Cryptography) is probably not an option. Furthermore, what is the platform of your Oracle server (JVM on IBM z/OS is buggy to say at least)? What is your JVM version on your client machine and what is the JVM version inside Oracle? Do they differ?

Cheers
Re: Problem while accessing java code from oracle [message #217215 is a reply to message #217212] Thu, 01 February 2007 03:51 Go to previous messageGo to next message
agrawal_vaibhao
Messages: 20
Registered: May 2006
Junior Member

Hi,
Code for Encrypt Function is as :-
---------------------------------------------------------------------------------
CREATE OR REPLACE Function Encrypt(p_String In Varchar2) Return Varchar2 As
Language Java Name 'Crypto.encrypt(java.lang.String) return java.lang.String';
----------------------------------------------------------------------------------

Regarding Platform, we r using JVM.

And JVM version on your client machine and JVM version inside Oracle are same.

Actually in java code we are calling some file that that contain encryption key.
i have loaded that file also using loadjava.
Is there may be problem while refering to that file?

If i hardcode encryption key in my java code then its working, so is there any issue related
to that ?
Re: Problem while accessing java code from oracle [message #217223 is a reply to message #217215] Thu, 01 February 2007 04:12 Go to previous message
sdecman
Messages: 20
Registered: July 2005
Location: Ljubljana, Slovenia
Junior Member
Quote:

Actually in java code we are calling some file that that contain encryption key.
i have loaded that file also using loadjava.
Is there may be problem while refering to that file?



Maybe, I have never tried to read file inside Oracle. However this is wrong approach right from the start. I would use Oracle's built-in functions (DBMS_CRYPTO package) and that would eliminate the need for java in the first place.

But if you insist using java for encryption, I would advise you to store the encryption key inside Oracle table (not inside a file!). It would ease the administration of the key greatly because you would need just one simple update to change that key -- not the new file upload.

But me not being the best security expert, I would think that the best key storage would be not to store the key at all... If the key doesn't change on regular basis might as well be hard coded.

Cheers
Previous Topic: Update date field using execute immediate statement..
Next Topic: Query
Goto Forum:
  


Current Time: Sat Dec 10 06:43:02 CST 2016

Total time taken to generate the page: 0.04590 seconds