Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and the fly likes Apache Derby data base DECIMAL converting to BigDecimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Apache Derby data base DECIMAL converting to BigDecimal" Watch "Apache Derby data base DECIMAL converting to BigDecimal" New topic

Apache Derby data base DECIMAL converting to BigDecimal

Steve Howerton
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
When I extract a inserted record(apache Derby embeded db) to view it I load a DECIMAL datatype of 100.00 from the database to the controller variable payRate with data type BigDecimal.

The database loads a BIGDECIMAL from this controller just fine. but the data type is noted as DECIMAL(5,2) in the table createion. Is there a code example other than the API that could explain how to store 100.00 (DECIMAL from the database) to a data Type

BIGDECIMAL In the controller. Does a scale have to be established or some kind of rounding of the
value coming from database have to happen? I can not understand the rounding or mathContext() descriptions in Class BigDecimal or Enum Rounding Class.

I can not understan why the data types are compatable on insert but if I pull the value out
It will not load the same vaiable.

Before the insert the bean contains: Data type= BigDecimal

The bean value is inserted into the table of data type:

result output :inserted into database (apache derby embedded)

when I then select the record back out to look at it:

When I extract the same record to view it I load a controller

my application at this early stage will not deal with any complex math.everything is rounded
to two decimal places ex(25.00)

I probably should change the data types to BIGINT (apache derby)

is there a way to continue with BIGDECIMAL? Would there be any advantage later if the math gets more complex? Or would BIGINT handle the basics?

Paul Clapham

Joined: Oct 14, 2005
Posts: 18570

Well, regardless of all that, there's a good chance that "rs.getBigDecimal(12)" is just attempting to get data from some other field because you miscounted your columns. However you didn't post the query so it's impossible for anybody but you to confirm that.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19693

I'll move this thread to our JDBC forum.

How To Ask Questions How To Answer Questions
Steve Howerton
Ranch Hand

Joined: Oct 18, 2011
Posts: 41

I Looked at it fresh this morning and clearly the SELECT statement (above) indeed it is
trying to load rs.getBigDecimal(12) by accessing the admin_area_code field. So I will
stick with BIGDECIMAL. I am not certain but in my limited understanding of the math concepts
of BIGINT and BIGDECIMAL and the math I may inject into the App. I am under the impression
that BIGDECIMAL will handle a wider variety of mathematical calculations.
Thanks for your time.

output of the bean contents:
I agree. Here's the link:
subject: Apache Derby data base DECIMAL converting to BigDecimal