SingleConnectionDataSource scds = null;
try {
scds = new SingleConnectionDataSource(jdbcTemplate.getDataSource().getConnection(), true);
} catch (SQLException e) {
e.printStackTrace();
throw new BusinessRuntimeException("创建 single connnection ds 失败", e);
}
JdbcTemplate jdbc = new JdbcTemplate(scds);
使用时要手动调用destroy方法将连接放回连接池:
try{
}catch (Exception e) {
throw new BusinessRuntimeException("查询出错:"+e);
}finally {
scds.destroy();
}