tags:

views:

28

answers:

2

I'm using JDBC to access a MySQL 4.1 database and have problems with queries of Decimal type. When I do a query on a single Decimal column (i.e., SELECT amount AS v FROM Customer) I get a BigDecimal through the JDBC driver, but when I do an an operation of Decimal columns (i.e., SELECT amount + tax AS v FROM Customer) I get a Double even all columns involved in the operation are Decimal. Is there ay way in which I can Convert or Cast the result to a Decimal. I've tried CAST and CONVERT unsuccessfully.

+1  A: 

Some JDBC drivers allow to receive the value as several types (for example, you can call rs.getString(), even though the value is an INTEGER). Try to call getObject() or getBigDecimal() on the column and check what you get.

Aaron Digulla
I'm relying on an introspection framework in which the calls are always `getObject()` and can't change that. I would need the returning result set to come as Decimal.
rmarimon
In that case, `case (amount+tax as decimal(13,4)) as v` *should* work :-/
Aaron Digulla
Cast as decimal does not work in 4.1.
rmarimon
+1  A: 

Have a look at the ROUND() function:

Quote:

The return type is the same type as that of the first argument (assuming that it is integer, double, or decimal).

This might work if it considers one of your columns to be the first argument, rather than the result of the expression.

Mike
Will give this a try.
rmarimon