Data Conversion Models

Choose the conversion model that best matches your Oracle data types and your application needs. In general, prefer the option that requires the least conversion and validation in your Java code.

Example: Oracle NUMBER can represent a very wide numeric range and precision. Only java.math.BigDecimal can represent the full range without losing information. Using java.math.BigDecimal may introduce additional conversion and validation overhead, but it guarantees that values are not truncated and that NULL values can be represented safely.

Integer Conversion Models

  • int: 32-bit integer. Input parameters may be NULL (autoboxed), but outputs and transfer object fields are primitive int and therefore cannot be NULL. If the database returns NULL, a NullPointerException will occur. Range overflow results in an ArithmeticException.
  • java.lang.Integer: 32-bit integer with NULL support for both input and output. Range overflow results in an ArithmeticException.
  • long: 64-bit integer. Input parameters may be NULL (autoboxed), but outputs and transfer object fields are primitive long and cannot be NULL. If the database returns NULL, a NullPointerException will occur. Range overflow results in an ArithmeticException.
  • java.lang.Long: 64-bit integer with NULL support for both input and output. Range overflow results in an ArithmeticException.
  • java.math.BigDecimal: Preserves full database precision and supports NULL values. Note that it can represent values with more precision than your database column definition allows.

Floating-Point Conversion Models

  • double: 64-bit floating-point. Input parameters may be NULL (autoboxed), but outputs and transfer object fields are primitive double and cannot be NULL. If the database returns NULL, a NullPointerException will occur.
  • java.lang.Double: 64-bit floating-point with NULL support for both input and output.
  • java.math.BigDecimal: Preserves full database precision and supports NULL values. Note that it can represent values with more precision than your database column definition allows.

Date Conversion Models

  • java.sql.Date: No conversion.
  • java.util.Date: Converts to/from java.util.Date.
  • java.time.LocalDate: Converts to/from java.time.LocalDate (Java 8+). Note: time information is lost.
  • java.time.LocalDateTime: Converts to/from java.time.LocalDateTime (Java 8+).

Timestamp Conversion Models

  • java.sql.Timestamp: No conversion.
  • java.time.LocalDate: Converts to/from java.time.LocalDate (Java 8+).
  • java.time.LocalDateTime: Converts to/from java.time.LocalDateTime (Java 8+).

Timestamp with (Local) Time Zone Conversion Models

  • java.time.ZonedDateTime: Converts to/from java.time.ZonedDateTime (Java 8+). Requires the Oracle 21c JDBC driver, but can still be used against older Oracle Database versions.