Use a DataSource to create a connection pool. - Java JDBC

Java examples for JDBC:DataSource

Introduction

The DataSource object must have been implemented and deployed to an application server environment.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {
    public Connection getDSConnection() { 
        Connection conn = null; 
        try { 
            Context ctx = new InitialContext(); 
            DataSource ds = (DataSource)ctx.lookup("jdbc/myOracleDS"); 
            conn = ds.getConnection(); 
    
        } catch (NamingException | SQLException ex) { 
            ex.printStackTrace(); 
        } 
        return conn; 
    } 
}

Related Tutorials