allen501pc / jlibs

Automatically exported from code.google.com/p/jlibs
0 stars 0 forks source link

Connection is closed exception in JDBC #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is my DAO class, basically same as on the Wiki page 
(http://code.google.com/p/jlibs/wiki/DAOPattern):

public class KeywordDAO {

   public static final DataSource DATA_SOURCE;
   public static final DAO<Keyword> KEYWORDS;

   static {
      System.setProperty("jlibs.jdbc.debug", Boolean.TRUE.toString());
      DataSource ds = null;
      try {
         Context initCtx = new InitialContext();
         Context envCtx = (Context) initCtx.lookup("java:comp/env");
         ds = (DataSource) envCtx.lookup("jdbc/tv"); //using datasource from tomcat, same problem with BasicDataSource
      } catch (NamingException ex) {
         Logger.getLogger(KeywordDAO.class.getName()).log(Level.SEVERE, null, ex);
      }
      DATA_SOURCE = ds;
      KEYWORDS = DAO.create(Keyword.class, new JDBC(DATA_SOURCE));
   }
}

This is how I invoke the DAO:
KeywordDAO.KEYWORDS.all();

The problem is that every other invoke results in a "java.sql.SQLException: 
Connection is closed". I've fixed this problem easily by modifying the 
jlibs.jdbc.JDBC class, specifically the method:

public <T> T run(int batchInterval, JDBCTask<T> task) throws DAOException

so that after every call to con.close() (there are 2 of those currently in the 
method) a CONNECTION.set(null) is called.

Original issue reported on code.google.com by vanjadar...@gmail.com on 21 Apr 2013 at 8:53

GoogleCodeExporter commented 9 years ago
fixed in r1763

Original comment by santhosh.tekuri@gmail.com on 23 Apr 2013 at 10:07