title: c3p0 connection pooling full eventhough connection is closed
body: <p>I have this problem with c3p0 connection pooling, i am new with c3p0.</p>
  
  <p>My desktop program use java with mssql 2008r2
  the jdbc driver i use is jtds
  and for the connection pooling i use c3p0</p>
  
  <p>i have some problem when the program is running for some time, the program is stuck because it is waiting to get connection from the pool.</p>
  
  <p>it seems that the connection pool is full, so that the sql statement cannot be executed.
  i already close the connection every time i have finished execute the sql statement.</p>
  
  <p>does anyone having this same problem with c3p0 ?</p>
  
  <p>note :
  i use ComboPooledDataSource and when i want to get some connection, i use the ComboPooledDataSource, getConnection() method. this getConnection() method from ComboPooledDataSource, does it get the idle connection?</p>
  
  <p>how to make connection to idle? because i already close the connection everytime i get the connection.</p>
  
  <p>Thanks.</p>
  
  <p>here's the code i use:
  generally i have 2 class:
  1.for the database connection (to get connection and the pooling)
  2.for the database transaction (to execute query statement)</p>
  
  <pre><code>public final class DBConnection {
  private static DatabaseProperties dbProp;
  private static ComboPooledDataSource ds;
  
  private DBConnection(){}
  
  private static void create(){
      DatabaseProperties dp = getDatabaseProperties();
      boolean success = true;
  
      do{
          try{
              ds = new ComboPooledDataSource();
              ds.setDriverClass("net.sourceforge.jtds.jdbc.Driver");
              ds.setJdbcUrl("jdbc:jtds:sqlserver://"+ dp.getIpaddr()+":"+dp.getPort()+ "/"+dp.getDbname(););
              ds.setUser(dp.getUsername());
              ds.setPassword(dp.getPassword());
  
              ds.setMinPoolSize(3);
              ds.setAcquireIncrement(1);
              ds.setMaxPoolSize(20);
          } catch (Exception ex) {
              LoggerController.log(Level.SEVERE,"Database error on creating connection",ex,LoggerController.DATABASE);
              success = false;
          }
      }while(!success);
  }
  public static ComboPooledDataSource getDataSource(){
      if(ds == null)create();
  
      return ds;
  }
  
  public static Connection getConnection(){
      Connection con = null;
      try {
          con = DBConnection.getDataSource().getConnection();
      } catch (SQLException ex) {
          LoggerController.log(Level.SEVERE,"Database error on getting connection",ex,LoggerController.DATABASE);
      }
  
      return con;
  }
  
  public static void close(){
      ds.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class DBTrans {
  private DBTrans(){}
  
  public static DataTable executeQuery(String query) throws SQLException{
      DataTable dt = null;
      Connection con = null;
      try {
          con = DBConnection.getConnection();
          Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery(query);
          dt = new DataTable(rs);
      } catch (SQLException ex) {
          throw new SQLException("QUERY= ["+query+"]\n"+ex.getMessage());
      }
      finally{
          if(con!=null){
              con.close();
          }
      }
      return dt;
  }
  
  public static int executeUpdate(String query) throws SQLException{
      int sql = 0;
      Connection con = null;
      try {
          con = DBConnection.getConnection();
          Statement stmt = con.createStatement();
          sql = stmt.executeUpdate(query);
          con.close();
      } catch (SQLException ex) {
          throw new SQLException("QUERY=["+query+"]\n"+ex.getMessage());
      }
      finally{
          if(con!=null){
              con.close();
          }
      }
      return sql;
  }
  </code></pre>
  
  <p>}</p>