This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Java equivalent of NUMERIC(2,2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java equivalent of NUMERIC(2,2)" Watch "Java equivalent of NUMERIC(2,2)" New topic

Java equivalent of NUMERIC(2,2)

Kristofer Hindersson

Joined: Jan 19, 2010
Posts: 25
What is the java-representation of the SQL-type NUMERIC(2,2)? The column is meant to hold a value representing time (e.g. number of years). I've seen examples were BigDecimal is used as a wrapper but that seems like overkill in this case.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3700

You can you integer type such as (int) or (short). For example, monetary values are often stored in cents (multiplied by 100) so that no decimals are needed. You could also use float for less precision than double, but that's about it.

If you need something that strongly behaves like NUMERIC(2,2), such as enforcing constraints, etc, you should write your own wrapper class.

My Blog: Down Home Country Coding with Scott Selikoff
Kristofer Hindersson

Joined: Jan 19, 2010
Posts: 25
Thank you! Quick and informative, just the way I like it.
I agree. Here's the link:
subject: Java equivalent of NUMERIC(2,2)
Similar Threads
Regarding Files Names
Help with Db2JdbcDriver
Does java has java.sql.Types.NUMERIC type?