Run the testing program again, and it will yield the following output (other outputs were omitted):
Contact - Id: 1, First name: Clarence, Last name: Ho, Birthday: 1980-07-30
---Contact Tel Detail - Id: 2, Contact id: 1, Type: Home, Number: 1234567890
---Contact Tel Detail - Id: 1, Contact id: 1, Type: Mobile, Number: 1234567890
Contact - Id: 2, First name: Scott, Last name: Tiger, Birthday: 1990-11-02
---Contact Tel Detail - Id: 3, Contact id: 2, Type: Home, Number: 1234567890
Contact - Id: 3, First name: John, Last name: Smith, Birthday: 1964-02-28
You can see the contacts and their telephone details were listed accordingly. The data is based on
the data population scripts in Listing 8-2.
So far, you have seen how to use JdbcTemplate to perform some common query operations.
JdbcTemplate (and the NamedParameterJdbcTemplate class too) also provides a number of overloading
update() methods that support data update operations, including insert, update, delete, and so on.
However, the update() method is quite self-explanatory, so we decide not to cover it in this section.
On the other side, as you will see in later sections, we will use the Spring-provided SqlUpdate class to
perform data update operations.
Spring Classes That Model JDBC Operations
In the preceding section, you saw how JdbcTemplate and the related data mapper utility classes had
greatly simplified the programming model in developing data access logic with JDBC. Built on top of
JdbcTemplate, Spring also provides a number of useful classes that model JDBC data operations and let
developers maintain the query and transformation logic from resultset to domain objects in a more
object-oriented fashion. As mentioned, those class are packaged under
org.springframework.jdbc.object. Specifically, we will discuss the following classes:
MappingSqlQuery<T>: The MappingSqlQuery<T> class allows you to wrap the
query string together with the mapRow() method into a single class.
SqlUpdate: The SqlUpdate class allows you to wrap any SQL update statement
into it. It also provides a lot of useful functions for you to bind SQL parameters,
retrieve the RDBMS-generated key after a new record is inserted, and so on.
BatchSqlUpdate: As the name implies, the class allows you to perform batch
update operations. For example, you can loop through a Java List object and
have the BatchSqlUpdate queue up the records and submit the update
statements for you in a batch. You can set the batch size and flush the operation
anytime as you want.
SqlFunction<T>: The SqlFunction<T> class allows you to call stored functions in
the database with argument and return types. Another class, StoredProcedure,
also exists that helps you invoke stored procedures.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home