liveBook · Manning

JDBC

As explained in Java Persistence with Spring Data and Hibernate epub

JDBC is the standard Java API for connecting to relational databases and executing SQL statements.

JDBC (Java Database Connectivity) is the Java API used to issue SQL statements to a relational database. Whether SQL is handwritten or generated by Java code, JDBC handles low-level work such as binding query parameters, executing queries, navigating results, and retrieving values. That work is necessary for data access, but it is often not the business logic an application is trying to express. section 1.1.3

Choosing where to handle that work changes the persistence code:

  • With direct JDBC, application code must manage service tasks such as opening and closing connections and handling exceptions. section 15.0
  • Hibernate and JPA address object/relational mapping so code can work with persistent objects rather than hand-code every CRUD operation in SQL and JDBC. section 1.0 section 1.1.3
  • Spring Data JDBC offers JDBC-based repositories and SQL queries with a simpler, more limited mapping model than JPA: it has no caching, lazy loading, sessions, or dirty tracking, and entities must be saved explicitly. section 15.0

JDBC also provides a partial abstraction over vendor-specific SQL data types. Hibernate can use ANSI-standard types when executing INSERT and UPDATE statements, while its configured SQL dialect translates types for product-specific schema generation. That distinction matters when working with an existing schema or writing vendor-specific SQL; Spring Data JDBC queries use plain SQL and do not gain query portability from its repository API. section 6.3.1 section 15.0

A type-mapping boundary

A Java BigDecimal property maps to the standard SQL NUMERIC type. For schema generation with Hibernate’s H2 dialect, NUMERIC is translated to DECIMAL with precision and scale. JDBC helps abstract the data type used during data manipulation; the dialect determines the database-specific schema type. section 6.3.1

Table 6.1 Java primitive types that map to SQL standard types (view table figure)

Name

Java type

ANSI SQL type

integer

int, java.lang.Integer

INTEGER

long

long, java.lang.Long

BIGINT

short

short, java.lang.Short

SMALLINT

float

float, java.lang.Float

FLOAT

double

double, java.lang.Double

DOUBLE

byte

byte, java.lang.Byte

TINYINT

boolean

boolean, java.lang.Boolean

BOOLEAN

big_decimal

java.math.BigDecimal

NUMERIC

big_integer

java.math.BigInteger

NUMERIC

Compare Java numeric types with the ANSI SQL types used in Hibernate’s built-in mappings. section 6.3.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Identifies parameter binding, query execution, result handling, and connection-management costs without walking through a complete JDBC implementation.
Examples
Uses Java-to-ANSI-SQL numeric mappings and an H2 NUMERIC-to-DECIMAL dialect translation to illustrate type handling.
What it assumes
Assumes familiarity with Java applications and SQL databases, while spelling out the JDBC tasks involved in executing queries.
What you can do after
Evaluate/understand when direct JDBC’s service code or a JDBC-based repository’s simpler mapping model fits a persistence choice.
How it connects
Connects JDBC to SQL, object/relational mapping, Hibernate, JPA, Spring Data JDBC, and SQL dialects.

Also explained in

Compare how 2 books explain JDBC →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.