Code example for DataSource

Methods: getConnection

0
        //Initial connection pool 
        InitialContext initialContext = new InitialContext();
        Context context = (Context) initialContext.lookup("java:comp/env");
        //The JDBC Data source that we just created 
        DataSource ds = (DataSource) context.lookup("hoteldb");
        Connection connection = ds.getConnection();
 
        if (connection == null) {
            throw new SQLException("Error establishing connection!");
             
        } 
        return connection;
    } 
}