Java tutorial
/* * THIS PROGRAM IS GENERATED UNDER LICENSE FROM NEC CORPORATION. * * * $Date: $ * $Revision: $ * $Author: $ * */ package com.jp.systemdirector.projectzero.zab01.db.dao; import java.sql.Connection; import java.sql.SQLException; import javax.sql.DataSource; import org.springframework.context.ApplicationContext; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.web.context.ContextLoader; /** * Spring Connection ? * ??????????????? */ public class ConnectionUtilForSpring extends ConnectionUtil { private DataSource dataSource = null; private Connection conn = null; private Class daoCls; /** * <p></p> * @param daoCls ??? DAO */ public ConnectionUtilForSpring(Class daoCls) { this.daoCls = daoCls; } /** * <p>Connection ??</p> * @return Connection * @throws SQLException */ public Connection getConnection() throws SQLException { // ApplicationContext?dataSource? ApplicationContext context = ContextLoader.getCurrentWebApplicationContext(); dataSource = (DataSource) context.getBean("dataSource"); conn = DataSourceUtils.getConnection(dataSource); return conn; } /** * <p>Connection ? close ?</p> * @throws SQLException */ public void close() throws SQLException { // Spring ??????? connection ? close ????? } }