Skip to content

SR – Chapter 7

April 29, 2010
tags:

JDBC

Dao interface meant for dml operations naming method.add,edit,delete, search. Spring classes:

Testing org.springframework.jdbc.datasource.DriverManagerDataSourceProduction or commons-dbcp.jar OR c3p0 poolerJNDI :http://www.springframework.org/schema/jee
jee:jndi-lookup id=”dataSource” jndi-name=”jdbc/VehicleDS”
JDbcTemplate uses abstract classes like :PreparedStatementCreator,PreparedStatementSetter,BatchPreparedStatementSetter,

Searching: RowCallbackHandler, RowMapper (intfc),BeanPropertyRowMapper.newInstance, Single value (classname)

SimpleJdbcDaoSupport – has easy to use method – extend it.ParameterizedRowMapper – avoids typecasting.ParameterizedBeanPropertyRowMapper.newInstance(Vehicle.class)

Can use named properties in hashmap and pass as param. or use SqlParameterSource
array.BeanPropertySqlParameterSource is cool. User prop name as param name.
String sql = “INSERT INTO VEHICLE (VEHICLE_NO, COLOR, WHEEL, SEAT) “+ “VALUES (:vehicleNo, :color, :wheel, :seat)”;

Note the usage of :data instead of ?.

The Exceptions like SQLException are caught by Spring and converted into a Runtime exception so you do not declare them in method declaration (phew!!). One common top level exception in Spring is DataAccessException.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: