JDBC vs. JPA

Greg L. Turnquist
6 min readAug 3, 2022

In the land of software development, we sure love acronyms. Our acronyms in the land of Java-apps-talking-to-database, there is no shortage there.

And maybe this leads to confusion: What do I use? Everyone else is using JPA? Should I? But I heard about Spring Data JDBC? And what about Spring Data JPA?

In this article, we’ll talk about JDBC, JPA, where they came from, and the tradeoffs that exist.

Once, long ago, there was JDBC

JDBC is the Java Database Connectivity API. This is an old standard, going all the way back to the days of Java 1.1 in 1997. And this API has served us well.

It’s “old data”. Get it?

Everything, and I mean EVERYTHING that talks to databases goes through JDBC. And that has its pros and cons. Basically, JDBC is the Java implementation of the standard dance ALL technologies have played to interact with databases.

  1. Open connection.
  2. Open cursor.
  3. Submit query.
  4. Iterate over result set.
  5. Close result set/cursor.
  6. Close connection.

And we’ve all probably suffered the fate of implementing twenty queries, and forgetting to CLOSE one of those resources along the way. And then, six weeks later, getting a scary stack trace because somehow…

--

--

Greg L. Turnquist

Sr. Staff Technical Content Engineer at CockroachDB • YouTube Content Creator at https://youtube.com/@ProCoderIO • Best-Selling Author • Coffee Lover