Solved

java.math.BigDecimal  Error

Posted on 2004-04-27
8
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 10934025
print out the exception
0
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 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