aspose file tools*
The moose likes JDBC and the fly likes ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerExce Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerExce" Watch "ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerExce" New topic
Author

ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerExce

somenath chatterjee
Greenhorn

Joined: Mar 20, 2008
Posts: 16
Hi,

I am trying to call java method from oracle function to get hash code, please
refer the the code-

java code:
create or replace and compile java source named lookUpHash AS
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;

public class LookUpHash {

public static String getLHash(String colValue) {
String result = "";
try{
long l = 0;
String encryptValue = encrypt(colValue);
l = getHashCode(encryptValue);
result = String.valueOf(l);
}catch(Exception e){
e.printStackTrace();
}
return result;
}
public static String encrypt(String plainText){
BASE64Encoder encoder = null;
String encrypted = null;
byte[] keyBytes = "1234567890123456".getBytes();
try
{
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(256);
SecretKey skey = keyGen.generateKey();
SecretKeySpec KeySpec = new SecretKeySpec(keyBytes, "AES");
Cipher AesCipher = Cipher.getInstance(skey.getAlgorithm());
AesCipher.init(Cipher.ENCRYPT_MODE, KeySpec);

encoder = new BASE64Encoder();
byte[] CipherText = AesCipher.doFinal(plainText.getBytes());
encrypted = encoder.encode(CipherText);
return encrypted;
}
catch(Exception e){
System.out.println("Exception in encrypt: "+e);
e.printStackTrace();
}
return encrypted;
}
public static long getHashCode(String value)
{
char val[] = value.toCharArray();
long hash = 1;
int len = value.length();
int j = 1;
for (int i = 0; i < len; i++ )
{
hash = 1 + hash + (++j * 500) + val[i];
}
return hash;
}

}

and oracle function is :
create or replace
FUNCTION oo(name VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA NAME 'HashSomu.getLHash(java.lang.String) return String';

but it is gave: ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerException

I am sure it is return null value from encrypt().
please send me solution if any bady had faced this kind of problem.
Thank you
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
This usually happens because you have not been granted permission to the Oracle object you are trying to access.

Is the only ORA error you are receiving?
somenath chatterjee
Greenhorn

Joined: Mar 20, 2008
Posts: 16
Thank you for you reply. Can you please guide me for how granted permission to the Oracle object.
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
I will look it up after my meeting... though this isn't a warranty to fix it... their are other java errors that cause ora-29532. ;)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerExce