Skip to content
Ameen Abozaid
Planned lessonJNR-025-L03

Type mapping pitfalls

  • Lesson 3 of 5
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

map SQL column types to the right Java types.

Planned topics

  • Money: numeric(12,2) maps to BigDecimal, never double (binary floats cannot store 0.1 exactly).
  • Time: timestamptz maps to Instant or OffsetDateTime; date to LocalDate.
  • bigint maps to long; for nullable columns use getObject(col, Long.class) or check wasNull().
  • rs.getInt on a NULL silently returns 0.
  • Text columns map to String; PostgreSQL uuid maps to UUID.
Draft outline details

Demonstration

java
BigDecimal price = rs.getBigDecimal("price");
Instant created = rs.getObject("created_at", OffsetDateTime.class).toInstant();
Long categoryId = rs.getObject("category_id", Long.class); // null stays null

Check your understanding

Which Java type for a numeric(12,2) price?

Show answer

BigDecimal.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.