开发者

Force MySQL 4.1 return to Decimal type

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开发者_C百科 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜