• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for you reply. Can you please guide me for how granted permission to the Oracle object.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ;)
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic