package com.example;

import java.sql.*;

public class DBConn {
  // db settings
  public static final String DBHOST = "localhost";
  public static final String DATABASE = "lms2_development";
  public static final String DBUSER = "lms";
  public static final String DBPASS = "";

  public DBConn() {}

  public Connection get() {
    Connection conn = null;

    try
    {
      Class.forName("org.postgresql.Driver");
      String url = "jdbc:postgresql://" + DBHOST + "/" + DATABASE;
      conn = DriverManager.getConnection(url, DBUSER, DBPASS);
    }
    catch (ClassNotFoundException|SQLException e)
    {
      System.err.println(e.getMessage());
    }

    return conn;
  }
}
@@ -30,14 +30,514 @@
 java
+x
 .sql.
-*
+DataSource;%0Aimport java.sql.Connection;%0Aimport java.sql.Statement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0A%0Aimport org.apache.commons.pool2.ObjectPool;%0Aimport org.apache.commons.pool2.impl.GenericObjectPool;%0Aimport org.apache.commons.dbcp2.ConnectionFactory;%0Aimport org.apache.commons.dbcp2.PoolableConnection;%0Aimport org.apache.commons.dbcp2.PoolingDataSource;%0Aimport org.apache.commons.dbcp2.PoolableConnectionFactory;%0Aimport org.apache.commons.dbcp2.DriverManagerConnectionFactory
 ;%0A%0Ap
@@ -786,19 +786,37 @@
 lic 
-DBConn() %7B%7D
+static DataSource dataSource;
 %0A%0A  
@@ -822,16 +822,23 @@
  public 
+static 
 Connecti
@@ -856,47 +856,49 @@
     
-Connection conn = null;%0A%0A    try%0A    %7B%0A
+if (dataSource == null) %7B%0A      try %7B%0A%0A  
     
@@ -949,172 +949,283 @@
     
-String url = %22jdbc:postgresql://%22 + DBHOST + %22/%22 + DATABASE;%0A      conn = DriverManager.getConnection(url, DBUSER, DBPASS
+  dataSource = setupDataSource();%0A%0A      %7D catch (ClassNotFoundException e) %7B%0A%0A        System.err.println(e.getMessage());%0A%0A      %7D%0A    %7D%0A%0A    Connection conn = null;%0A%0A    try %7B%0A%0A      if (dataSource != null) %7B%0A        conn = dataSource.getConnection(
 );%0A    
+ 
-%7D
+ %7D%0A
 %0A   
+ %7D
  catch
- (ClassNotFoundException%7C
+(
 SQLE
@@ -1239,15 +1239,12 @@
 n e)
-%0A   
  %7B%0A
+%0A
     
@@ -1281,16 +1281,17 @@
 age());%0A
+%0A
     %7D%0A%0A 
@@ -1310,9 +1310,622 @@
 nn;%0A  %7D%0A
-%7D
+%0A  private static DataSource setupDataSource() %7B%0A    String connectURI = %22jdbc:postgresql://%22+DBHOST+%22/%22+DATABASE+%22?user=%22+DBUSER+%22&password=%22+DBPASS+%22&ssl=false%22;%0A%0A    ConnectionFactory connectionFactory =%0A      new DriverManagerConnectionFactory(connectURI, null);%0A%0A    PoolableConnectionFactory poolableConnectionFactory =%0A      new PoolableConnectionFactory(connectionFactory, null);%0A%0A    ObjectPool%3CPoolableConnection%3E connectionPool =%0A      new GenericObjectPool%3C%3E(poolableConnectionFactory);%0A%0A    poolableConnectionFactory.setPool(connectionPool);%0A%0A    return new PoolingDataSource%3C%3E(connectionPool);%0A  %7D%0A%7D%0A

Update DBConn to return pooled connection