Example usage for javax.sql ConnectionPoolDataSource getPooledConnection

List of usage examples for javax.sql ConnectionPoolDataSource getPooledConnection

Introduction

In this page you can find the example usage for javax.sql ConnectionPoolDataSource getPooledConnection.

Prototype

PooledConnection getPooledConnection() throws SQLException;

Source Link

Document

Attempts to establish a physical database connection that can be used as a pooled connection.

Usage

From source file:Main.java

private static Connection getConnection() throws NamingException, SQLException {
    InitialContext initCtx = createContext();
    String jndiName = "HrDS";
    ConnectionPoolDataSource dataSource = (ConnectionPoolDataSource) initCtx.lookup(jndiName);
    PooledConnection pooledConnection = dataSource.getPooledConnection();
    return pooledConnection.getConnection(); // Obtain connection from pool
}

From source file:PooledConnectionExample.java

private static Connection getConnection() throws NamingException, SQLException {
    InitialContext initCtx = createContext();
    String jndiName = "HrDS";
    ConnectionPoolDataSource dataSource = (ConnectionPoolDataSource) initCtx.lookup(jndiName);
    PooledConnection pooledConnection = dataSource.getPooledConnection();
    return pooledConnection.getConnection();
}