Solved

java.math.BigDecimal  Error

Posted on 2004-04-27
8
347 Views
Last Modified: 2010-08-05

I'm trying to map a handful of Sybase database columns of data type numeric(10,3) ie 10 digits of which 3 are decemical places onto java fields which are of type java double.

The mapping results in the error: java.math.BigDecimal  

This does not tell me very much , but I'm guessing that it is telling me that the mapped fileld is too large to fit into a java double and is throwing out the datatype it reckons it should be?

correct me if I'm wrong.

Could I then do this to manipulate the read in field?

  double mydouble1 = readInField1.doubleValue()

  double mydouble2 = readInField2.doubleValue()

etc

0
Comment
Question by:azsat
8 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10932263
How are you reading the values from the database? Please post the stacktrace!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10932269
Try to find out what kind of class it'd like to return

Object o = rs.getObject(index);
System.out.println(o.getClass().getName());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10932316
As it happens, this

>>readInField1.doubleValue()

should work for both Double and BigDecimal, but if the latter, and it's out of range, you'll get an infinity value returned.
0
 
LVL 92

Expert Comment

by:objects
ID: 10934025
print out the exception
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:Mayank S
ID: 10938235
>> data type numeric(10,3) ie 10 digits of which 3 are decemical places

Why do you need BigDecimal for such a small value, BTW?
0
 

Author Comment

by:azsat
ID: 10943451
Hi

My apologies I given insufficient info.  Here is a bit more detail - can you help?

the DB column is infact numeric(28,12) and is read into a java field declared as NUMERIC.  THe read in fields are held in a java dataset.

I then simply access each field in the dataset by its name using a a simpe method
callled fieldByName, which simply returns the specified field in the dataset.

dataset ds .......

  System.out.println(ds.fieldByName("column_1").doubleValue());


The NUMERIC field is held as a java BigDecimal in the dataset. I can't seem to find a sutible method to use with this BigDecimal to get back the correct value.

so the above stmt Converts this BigDecimal to a double.

colum1 on the DB is 1643546000.000000000000

the above print stmt returns 1.643546E9.

How can I return the correct (BigDecimal value) held in the dataset?










0
 

Author Comment

by:azsat
ID: 10943453
Hi

My apologies I given insufficient info.  Here is a bit more detail - can you help?

the DB column is infact numeric(28,12) and is read into a java field declared as NUMERIC.  THe read in fields are held in a java dataset.

I then simply access each field in the dataset by its name using a a simpe method
callled fieldByName, which simply returns the specified field in the dataset.

dataset ds .......

  System.out.println(ds.fieldByName("column_1").doubleValue());


The NUMERIC field is held as a java BigDecimal in the dataset. I can't seem to find a sutible method to use with this BigDecimal to get back the correct value.

so the above stmt Converts this BigDecimal to a double.

colum1 on the DB is 1643546000.000000000000

the above print stmt returns 1.643546E9.

How can I return the correct (BigDecimal value) held in the dataset?










0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 10943486
Depends on what you want to do with it. Here's one way

BigDecimal bd = (BigDecimal)rs.getObject(1);
System.out.println(bd);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 65
Requested array size exceeds VM limit 3 84
object oriented programming comparison 5 52
couple of eclipse 5 16
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now