aspose file tools*
The moose likes Beginning Java and the fly likes Retrieving a NUMBER column in resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Retrieving a NUMBER column in resultset " Watch "Retrieving a NUMBER column in resultset " New topic
Author

Retrieving a NUMBER column in resultset

Ashish Bassi
Greenhorn

Joined: Aug 22, 2007
Posts: 11
I have a column in Oracle db table

ACTIONFLAG NUMBER(19)

I need to retrieve this column from resultset and pass it in a java bean field of String dataType.

class Bean {

String actionFlag;

public setActionFlag(String af) {
...
}

}

From what I understand, ideally we should retrieve NUMBER columns using rs.getBigDecimal(),but i need to store the retrieved value in a String.

Which would be a better approach from a performance point of view.

1) bean.setActionFlag(rs.getString("ACTIONFLAG"))

or

2) bean.setActionFlaag(rs.getBigDecimal("ACTIONFLAG").setScale(0).toString());

Im using setScale(0) to remove decimal point because getBigDecimal returns 12.00 for a value 12 in table which i dont want. The column shall never hv any value with a decimal

or should i follow any other approach
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

... The column shall never hv any value with a decimal...

If you need only int values then whay don't you use INT as the column type?

And please UseRealWords when posting in the forums (eg: words like "hv" instead "have" make the reader confused).


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ashish Bassi
Greenhorn

Joined: Aug 22, 2007
Posts: 11
Its not something i can change, the table structure is in production for sometime and db team isnt willing to change this.
So i was jus looking at performance improvement opportunities at java sidr
 
wood burning stoves
 
subject: Retrieving a NUMBER column in resultset