Member-only story

Working with JDBCTemplate, If You Must

janac
5 min readMay 5, 2020

--

If you are starting a new Java project which requires persistence, I strongly recommend you use JPA or Hibernate instead of JDBC Template. But if you find yourself needing to fixing a legacy codebase that requires the use of JDBCTemplate, then this article is for you.

JDBCTemplate was confusing for me because the official documentation doesn’t provide examples, online tutorials were cluttered with XML and spelling mistakes, and there are so many options to pick from such as which query method to use:

Autocomplete suggestions for NamedParameterJDBCTemplate. This article only covers query().

By the end of this article, you will learn:

  • What is JDBCTemplate
  • How to do basic CRUD operations against a database using JDBCTemplate
  • How to pick between JDBCTemplate or NamedParameterJDBCTemplate
  • What are SQL query params, and how to map them
  • How to handle the results of the query
  • What are RowMappers, ResultSetExtractors, and other alternatives
  • How to troubleshoot errors which aren’t easy to search up online

Prerequisites

  • Basic understanding of Java 8
  • Already have configured a database and schema to experiment with

What is JDBCTemplate

--

--

janac
janac

Written by janac

Most of my writing is about software. I enjoy summarizing and analyzing books and self-help videos. I am senior software consultant at LazerTechnologies.com.

No responses yet