8.3.11 DECIMAL and NUMERIC
The JDBC types DECIMAL and NUMERIC are very similar. They both represent fixed-precision decimal values. ame="1007716"> The corresponding sql types DECIMAL and NUMERIC are defined in sql-92 and are very widely implemented. These sql types take precision and scale parameters. The precision is the total number of decimal digits supported,and the scale is the number of decimal digits after the decimal point. For most DBMSs,the scale is less than or equal to the precision. So for example,the value "12.345" has a precision of 5 and a scale of 3,and the value ".11" has a precision of 2 and a scale of 2. JDBC requires that all DECIMAL and NUMERIC types support both a precision and a scale of at least 15.
The sole distinction between DECIMAL and NUMERIC is that the sql-92 specification requires that NUMERIC types be represented with exactly the specified precision,whereas for DECIMAL types,it allows an implementation to add additional precision beyond that specified when the type was created. Thus a column created with type NUMERIC(12,4) will always be represented with exactly 12 digits,whereas a column created with type DECIMAL(12,4) might be represented by some larger number of digits.
The recommended Java mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal. The java.math.BigDecimal type provides math operations to allow BigDecimal types to be added,subtracted,multiplied,and divided with other BigDecimal types,with integer types,and with floating point types.
The method recommended for retrieving DECIMAL and NUMERIC values is ResultSet.getBigDecimal. JDBC also allows access to these sql types as simple Strings or arrays of char. Thus,Java programmers can use getString to receive a DECIMAL or NUMERIC result. However,this makes the common case where DECIMAL or NUMERIC are used for currency values rather awkward,since it means that application writers have to perform math on strings. It is also possible to retrieve these sql types as any of the Java numeric types.
https://docs.oracle.com/javase/6/docs/technotes/guides/jdbc/getstart/mapping.html
考虑用getString,这样也可以避免以后超出long的范围的问题。
原文链接:https://www.f2er.com/oracle/212436.html