Solved

java.math.BigDecimal  Error

Posted on 2004-04-27
8
354 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example using maven 12 56
Which non-HTML GUI front end to use with Java? 3 24
add projects t working set in maven 2 19
Problem to Alipay 10 43
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

839 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