Solved

java.math.BigDecimal  Error

Posted on 2004-04-27
8
351 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

770 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