Search code examples
oracle-databaseblazedsbigdecimal

blazeds converts BigDecimal to string


I have a Flex application that uses blazeds to connect to a Java backend. Using remoting, I give a call to an API to run a SELECT statement on a table (using conventional JDBC classes) in a Oracle database.

The table has 2 columns:

PRODUCT_CODE of type NVARCHAR2(32) and
DEMAND of type NUMBER(10, 0)

My Java API is as follows:

public List<?> getQueryResult(String query) {
  Connection conn = DriverManager.getConnection(connStr, userName, password);
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery(query);

  ArrayList<?> result = new ArrayList<?>();
  while(rs.next()) {
    Object[] itemArray = new Object[2];
    itemArray[0] = rs.getObject(1);
    itemArray[1] = rs.getObject(2);
    result.add(itemArray);
  }

  return result;
}

In my Flex side, I have a handler for result event of this remote operation:

private function onResult(e:ResultEvent) : void {
  var result:ArrayCollection = (e.result as ArrayCollection);
}

Strangely, the values corresponding to DEMAND column are automatically converted to string (I debugged to find out that in backend, these were BigDecimal)

Any suggestions?


Solution

  • Yes indeed, the BigDecimal from Java is converted to String in ActionScript, as you can read in the developer guide. There is no BigDecimal in ActionScript so it was the only option - you cannot convert any BigDecimal to int or float.

    If you are sure that your value represented as NUMBER(10,0) has values in the interval -2,147,483,648 - 2,147,483,647 you can convert it to an int in java - see the code below:

    itemArray[1] = ((BigDecimal)rs.getObject(2)).intValue();