Java Reference
In-Depth Information
if(rs!=null){
try {
rs.close();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
}
return policyList;
}
}
The mixed approach to persistence in eInsure (entity beans and straight JDBC) made
the business component vulnerable to change. As you can see in Listing 5-1, the direct
use of the JDBC API meant a lot of boilerplate code for establishing a connection, prepar-
ing SQL statements, setting parameters, executing the SQL, iterating over the result set to
prepare a list of Java objects, and finally releasing database resources. This last step is
critical and often neglected, causing connection leaks and resource wastage. If the
straight JDBC approach were used in all the DAO methods, it would result in significant
code duplication.
 
Search WWH ::




Custom Search