Solved

java.math.BigDecimal  Error

Posted on 2004-04-27
8
345 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
Comment Utility
How are you reading the values from the database? Please post the stacktrace!
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
Comment Utility
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
Comment Utility
print out the exception
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

772 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

9 Experts available now in Live!

Get 1:1 Help Now