Spring Book – Chapter 8 – Data Access


A SimpleJdbcCall is a multi-threaded, reusable object representing a call to a stored procedure or a stored function. It provides meta-data processing to simplify the code needed to access basic stored procedures/functions. All you need to provide is the name of the procedure/function and a Map containing the parameters when you execute the call. The names of the supplied parameters will be matched up with in and out parameters declared when the stored procedure was created.

The meta-data processing is based on the DatabaseMetaData provided by the JDBC driver. Since we rely on the JDBC driver this “auto-detection” can only be used for databases that are known to provide accurate meta-data.

The actual functionality is being handled using Spring’s JdbcTemplate by the way of delegation by SimpleJdbcCall class.

Listing 8-22. Usage of SimpleJdbcCall to execute a function to calculate loyalty points

Listing 8-23. Usage of SimpleJdbcCall to execute a procedure to generate customer number

Main features of SimpleJdbcCall can be summarized as below:

  • Simplify call to functions and procedures
  • Any database can be used by explicitly defining the parameters
  • Supported databases like Oracle, MySQL etc. provides automatic parameter configuration, which is really handy


This is a class in the package org.springframework.jdbc.object, which lets you encapsulate any SQL query in your application. Subclasses of this class must implement the newRowMapper(..) method to provide an object that can extract the results of iterating over the ResultSet created during the execution of the query. SqlQuery instances are thread-safe after their initialization is complete. The SqlQuery class is rarely used directly because the MappingSqlQuery subclass provides a much more convenient implementation for mapping rows to Java classes.

Listing 8-24. Usage of SqlQuery which encapsulates the actual SQL query


Similar to SqlQuery SqlUpdate encapsulates an SQL update. Like a query, update object is also reusable. The class provides number of update(..) methods which helps encapsulate a lot from the developer.

Listing 8-25. Usage of SqlUpdate which encapsulates the actual SQL query

Page Visitors: 10629

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 8 – Data Access

  1. Hi my friend! I wish to say that this article is awesome, nice written and come with approximately all important infos. Iˇ¦d like to peer more posts like this .

Leave a Reply

Your email address will not be published. Required fields are marked *