img
point of view--you just do not have time to code repetitive code in every DAO class. Instead, you want to
concentrate on writing code that actually does what you need the DAO class to do: select, update, and
delete the data. The more helper code you need to write, the more checked exceptions you need to
handle, and the more bugs you may introduce in your code.
This is where a DAO framework and Spring come in. A framework eliminates the code that does not
actually perform any custom logic and allows you to forget about all the housekeeping that needs to be
performed. In addition, Spring's extensive JDBC support makes your life a lot easier.
Spring JDBC Infrastructure
The code we discussed in the first part of the chapter is not very complex, but it is annoying to write, and
because there is so much of it to write, the likelihood of coding errors is quite high. It is time to take a
look at how Spring makes things easier and more elegant.
Overview and Used Packages
JDBC support in Spring is divided into the five packages detailed in Table 8-2; each handles different
aspects of JDBC access.
Table 8-2. Spring JDBC Packages
Package
Description
Contains the foundations of JDBC classes in Spring. It includes
org.springframework.jdbc.core
the core JDBC class, JdbcTemplate, which simplifies
programming database operations with JDBC. Several
subpackages provide support of JDBC data access with more
specific purposes (e.g., a JdbcTemplate class that supports
named parameters) and related support classes as well.
org.springframework.jdbc.datasource Contains helper classes and DataSource implementations that
you can use to run JDBC code outside a JEE container. Several
subpackages provide support for embedded databases, database
initialization, and various datasource lookup mechanisms.
Contains classes that help convert the data returned from the
org.springframework.jdbc.object
database into objects or lists of objects. These objects and lists
are plain Java objects and therefore are disconnected from the
database.
The most important class in this package is SQLException
org.springframework.jdbc.support
translation support. This allows Spring to recognize error codes
used by the database and map them to higher-level exceptions.
Contains classes that supports JDBC configuration within
org.springframework.jdbc.config
Spring's ApplicationContext. For example, it contains handler
class for the jdbc namespace (e.g., <jdbc:embedded-database>
tags).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home