1 21 package net.mlw.vlh.adapter.jdbc.spring.util; 22 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 28 import javax.sql.DataSource ; 29 30 import net.mlw.vlh.adapter.jdbc.util.StandardConnectionCreator; 31 32 import org.springframework.jdbc.datasource.DataSourceUtils; 33 import org.springframework.jdbc.support.JdbcUtils; 34 35 42 public class SpringConnectionCreator extends StandardConnectionCreator 43 { 44 45 public SpringConnectionCreator() 46 { 47 } 48 49 public SpringConnectionCreator(DataSource dataSource) 50 { 51 super(dataSource); 52 } 53 54 public Connection createConnection() throws SQLException 55 { 56 return DataSourceUtils.getConnection(getDataSource()); 57 } 58 59 public void close(ResultSet result, PreparedStatement statement, Connection connection) 60 { 61 JdbcUtils.closeResultSet(result); 62 JdbcUtils.closeStatement(statement); 63 DataSourceUtils.closeConnectionIfNecessary(connection, getDataSource()); 65 } 66 } | Popular Tags |