样板我有一个包含了沿线的很多重复的代码很多方法DAO类: -的Java删除重复尝试,捕捉,最后从DAO
public void method1(...) {
Connection conn = null;
try {
//custom code here
} catch (SQLException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} catch (QueryNotFoundException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} finally {
if (conn != null)
connectionPool.returnConnection(conn);
}
public void method2(...) {
Connection conn = null;
try {
//different custom code here
} catch (SQLException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} catch (QueryNotFoundException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} finally {
if (conn != null)
connectionPool.returnConnection(conn);
}
我想重组这一类把这个尝试,赶上,最后在一个地方,以避免重蹈覆辙。我怎么做到这一点?
是的,如果JdbcTemplate不是一个选项,那是我要提出的下一个模式+1) – 2010-12-16 11:06:46