// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.sql.*;

import org.apache.commons.dbcp.*;
import org.apache.commons.pool.impl.*;

public class UsePool {

    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        GenericObjectPool cp = new GenericObjectPool(null);
        DriverManagerConnectionFactory dmcf = new DriverManagerConnectionFactory("jdbc:mysql://localhost/Test", "", "");
        PoolableConnectionFactory pcf = new PoolableConnectionFactory(dmcf, cp, null, null, false, true);
        PoolingDataSource ds = new PoolingDataSource(cp);
        Connection con = ds.getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM T1");
        while(rs.next()) {
            int f1 = rs.getInt(1);
            String f2 = rs.getString(2);
            System.out.println(f1 + " " + f2);
        }
        rs.close();
        stmt.close();
        con.close();
    }
}
