title: Implement Connection pooling in JDBC using apache dbcp
body: <p>Is this Good Code to implement pooling? I want to implement this in my project which has 30 threads  operating concurrently and each thread requires more than four connection for each request? Does this code work?     </p>
  
  <pre><code>    import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import java.sql.Connection;
  import java.sql.SQLException;
  import org.apache.commons.dbcp.BasicDataSource;
  
  /**
   *
   * @author
   * taher_JAVAHUNTER
   */
  
      public class JDBCHelper {
  
          private final static String username = "root";
          private final static String password = "";
          private final static String url = "jdbc:mysql://localhost:3306/treamisdemo";
          public static Connection connection = null;
          public static int connectionCount = 0;
      //    public JDBCHelper(boolean setCon) {
      //        try {
      //            setConnectionTest();
      //        } catch (Exception e) {
      //            System.out.println("Error in Connection:" + e.toString());
      //        }
      //    }
          public static BasicDataSource dataSource;
  
          public static Connection getConnection() throws SQLException {
              try {
                  if (dataSource == null) {
                      dataSource = new BasicDataSource();
                      String driver = "com.mysql.jdbc.Driver";
                      try {
                          dataSource.setDriverClassName(driver);
                          dataSource.setUrl(url);
                          dataSource.setUsername(username);
                          dataSource.setPassword(password);
                          dataSource.setMaxActive(100);
                          dataSource.setMaxWait(10000);
                          dataSource.setMaxIdle(10);
                          if (connection == null || connection.isClosed()) {
                              System.out.println(" requeition CONNECTION WITH FIRST SERVER.");
                              connection = dataSource.getConnection();
                              connectionCount++;
                          }
                      } catch (SQLException e) {
                          System.out.println("***Connection Requisition*** Could not connect to the database msg :" + e.getMessage());
                      }
                  } else {
                      connection = dataSource.getConnection();
                      connectionCount++;
                  }
              } catch (Exception e) {
                  System.out.println("open connection exception" + e);
              }
              return connection;
          }
  
          public static void close(ResultSet c) {
              try {
                  if (c != null) {
                      c.close();
                  }
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
  
          public static void close(Statement c) {
              try {
                  if (c != null) {
                      c.close();
                  }
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
  
          public static void close(Connection c) {
              try {
                  if (c != null) {
                      c.close();
                  }
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
  
  }
  </code></pre>