title: Jboss datasource recovering after database re-start
body: <p>Closed connections still in the connection pool - why?</p>
  
  <p>servlet-</p>
  
  <pre><code>public class Index extends HttpServlet {
  
      TimeZoneService timeZoneService;
  
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
          WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
          timeZoneService = (TimeZoneService) ctx.getBean("timeZoneService");
          timeZoneService.loadAllTimeZones();
          System.out.println("Done");
      }
  }
  
  public interface TimeZoneService {
      void loadAllTimeZones();
  }
  
  public class TimeZoneServiceImpl implements TimeZoneService {
  
      private TimeZoneDao tzDao;
      private Map&lt;Long, String&gt; tzOid2JavaName = new HashMap&lt;Long, String&gt;();
  
      public void loadAllTimeZones() {
          List&lt;TimeZone&gt; timeZones = tzDao.findAllTimeZones();
          for (TimeZone tz : timeZones) {
              tzOid2JavaName.put(tz.getOid(), tz.getJavaName());
          }
      }
  
      public void setTzDao(TimeZoneDao tzDao) {
          this.tzDao = tzDao;
      }
  }
  
  public interface TimeZoneDao {
      List&lt;TimeZone&gt; findAllTimeZones() throws DataAccessException;  
  }
  
  public class TimeZoneDaoImpl extends JdbcDaoSupport implements TimeZoneDao {
  
      public List&lt;TimeZone&gt; findAllTimeZones() throws DataAccessException
      {
          StringBuffer sql = new StringBuffer();
          sql.append("SELECT TZ.OID, TZ.JAVA_NAME FROM TIME_ZONE TZ");
          List&lt;TimeZone&gt; timeZones = getJdbcTemplate().query(sql.toString(), new RowMapper() {
              public Object mapRow(ResultSet rs, int i) throws SQLException {
                  TimeZone tz = new TimeZone();
                  tz.setOid(rs.getLong("OID"));
                  tz.setJavaName(rs.getString("JAVA_NAME"));
                  return tz;
              }
          });
  
          return timeZones;
      }
  }
  
  public class TimeZone {
      private Long oid;
      private String javaName;
  
      public Long getOid() {
          return this.oid;
      }
  
      public void setOid(Long oid) {
          this.oid = oid;
      }
  
      public String getJavaName() {
          return this.javaName;
      }
  
      public void setJavaName(String javaName) {
          this.javaName = javaName;
      }
  }
  </code></pre>
  
  <p>spring-config.xml</p>
  
  <pre><code>&lt;beans&gt;
  
      &lt;jee:jndi-lookup id="dataSource" jndi-name="java:/OracleDS"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="timeZoneDao" class="dao.impl.TimeZoneDaoImpl"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="timeZoneService" class="logic.impl.TimeZoneServiceImpl"&gt;
          &lt;property name="tzDao" ref="timeZoneDao"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app&gt;
  
      &lt;display-name&gt;Spring&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              WEB-INF/spring-config.xml,classpath*:/META-INF/spring-config.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;index&lt;/servlet-name&gt;
          &lt;display-name&gt;Index page&lt;/display-name&gt;
          &lt;description&gt;Landing page&lt;/description&gt;
          &lt;servlet-class&gt;servlet.Index&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;index&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/index&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- Session Timeout (in minutes) --&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;60&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>mysql-ds.xml</p>
  
  <pre><code>&lt;datasources&gt; 
     &lt;local-tx-datasource&gt; 
        &lt;jndi-name&gt;OracleDS&lt;/jndi-name&gt; 
        &lt;connection-url&gt;jdbc:mysql://localhost:3306/spring&lt;/connection-url&gt; 
        &lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt; 
        &lt;user-name&gt;spring_test&lt;/user-name&gt; 
        &lt;password&gt;spring_test13&lt;/password&gt; 
        &lt;min-pool-size&gt;1&lt;/min-pool-size&gt; 
        &lt;max-pool-size&gt;5&lt;/max-pool-size&gt; 
        &lt;idle-timeout-minutes&gt;2&lt;/idle-timeout-minutes&gt; 
     &lt;/local-tx-datasource&gt; 
  &lt;/datasources&gt;
  </code></pre>