tags:

views:

35

answers:

3

i m trying to insert a BigInteger value in the oracle database.i m trying like this:

BigInteger a=new BigInteger("4280972057205720579205792572075927209857");
String str=new String(a.toByteArray());

now in the database :

 PerparedStatement pstmt=con.prepareStatement("insert into database values(?)");
 pstmt.setString(1,str);
pstmt.executeUpdate();

if i m using str="hello" then it is working fine.but if i m using str=new String(a.toByteArray()) then nothing(null) is inserted in the database.why it is so.please explain and also suggest some method to do so.

+3  A: 

Documentation for BigInteger.toByteArray():

Returns a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element.

This has nothing to do with representing it in Decimal! You want to use BigInteger.toString() to get the string.

Mark Peters
A: 

why not use a.toString(); ?

Imre L
i tried and it is working.but i want to know that what was flaw in the previous approach.
Bipul
A: 

What is the difference with your previous post?

http://stackoverflow.com/questions/3052772/how-to-store-biginteger-values-in-oracle-database

Fred
actually i trid using converting BigInteger to bytearray and byteArary to string and it worked for some time.but i don't know how another day value was not being inserted another day where i had not modified a single line of code.i m clueless
Bipul