Type mapping pitfalls
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 toBigDecimal, neverdouble(binary floats cannot store 0.1 exactly). - Time:
timestamptzmaps toInstantorOffsetDateTime;datetoLocalDate. bigintmaps tolong; for nullable columns usegetObject(col, Long.class)or checkwasNull().rs.getInton a NULL silently returns 0.- Text columns map to
String; PostgreSQLuuidmaps toUUID.
Draft outline details
Demonstration
BigDecimal price = rs.getBigDecimal("price");
Instant created = rs.getObject("created_at", OffsetDateTime.class).toInstant();
Long categoryId = rs.getObject("category_id", Long.class); // null stays nullCheck 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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.