Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    4

    Unanswered: Issue with resultsset getBigDecimal scale

    HI
    I have a NUMBER column on Oracle 11g (11.2.0.3) declared as 15.5

    If I store as a number 10 when I try to read it using JDBC driver,
    the driver return a BigDecimal but with scale 0

    Code:
    BigDecimal vBigDecimal = vRS.getBigDecimal("MYNUMER155");
    // vBigDecimal.scale() = 0!! but it must be 5
    Reading the specification it says that it must return a big decimal with the full precision (so 5) but instead it return the "best" precision

    if the value for example is 11.2 the scale is 1
    if the value is 11.23 the scale is 2 and so on..

    I believe it is a bug in oracle (server or JDBC driver).. or there are some setting to apply to the jdbc url connection or server ?

    Thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    No it's not a bug. BigDecimal.getScale() returns the scale of its value not of the underlying database column (in fact the BigDecimal instance has not idea that it was created from a database value).

    You are looking for ResultSetMetaData.getScale()

    ResultSetMetaData (Java Platform SE 6)

  3. #3
    Join Date
    Apr 2012
    Posts
    4
    Thanks but..

    ResultSet (Java Platform SE 6))

    ResultSet.getBigDecimal says
    "Returns:the column value (full precision); if the value is SQL NULL, the value returned is null in the Java programming language
    "

    So it should return a big decimal with scale 5 and not depending of the value from my point of view

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by rmazzola View Post
    So it should return a big decimal with scale 5 and not depending of the value from my point of view
    Where does it say that?
    It simply says the value is returned with the full precision. So the value is not truncated or rounded in any way.
    It does not claim that's the defined precision for the column.

    My understanding is that the part "full precision" distinguishes this method from those (deprecated ones) that return the value with a given precision.
    ResultSet (Java Platform SE 6)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •