DBCP Connection Pooling Example

DBCPDataSourceExample.java

package com.dataSource.dbcp;

import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBCPDataSourceExample  {

   
public static void main(String[] args) throws PropertyVetoException, SQLException, IOException {
       
Connection connection = null;
        Statement statement =
null;
        ResultSet resultSet =
null;
       
try {
           
connection = DataSource.getInstance().getConnection();
            statement = connection.createStatement
();
            resultSet = statement.executeQuery
("select * from employee");
            
while (resultSet.next()) {
                
System.out.println("employeeid: " + resultSet.getString("employeeid"));
                 System.out.println
("employeename: " + resultSet.getString("employeename"));
            
}
        }
catch (SQLException e) {
           
e.printStackTrace();
       
} finally {
           
if (resultSet != null) try { resultSet.close(); } catch (SQLException e) {e.printStackTrace();}
           
if (statement != null) try { statement.close(); } catch (SQLException e) {e.printStackTrace();}
           
if (connection != null) try { connection.close(); } catch (SQLException e) {e.printStackTrace();}
        }

    }

}
Output
employeeId: 1
employeename: Rockey
employeeId: 2
employeename: Jose

 





Previous 1 2








2 Responses to "DBCP Connection Pooling Example"
  1. Chad Paul 2018-02-09 18:33:24.0
  1. ron 2019-07-17 00:21:27.0

Your email address will not be published. Required fields are marked *