JDBC Connection Pool

JDBC Connection Pool for GlassFish and Payara

GlassFish and Payara provide native JDBC connection pooling to reuse database connections, reduce connection-creation overhead, and improve the performance of database-driven Java applications.

Create the Environment

1

Open the topology wizard

Click New Environment in the platform dashboard.

2

Select the Java application server and database

Open the Java tab, select GlassFish or Payara, and add the required database server. The documented example uses GlassFish with MySQL.

3

Create the environment

Configure the resource limits and environment name, then click Create.

Create the Database and User

1

Open the database administration panel

Click Open in Browser beside the database node and sign in with the credentials supplied by the platform.

2

Add a database user

For MySQL, open the User accounts tab and click Add user account.

3

Create the database

Enter the username, password, and host permissions. Enable the option to create a database with the same name and grant all privileges, then save the account.

Create the JDBC Connection Pool

1

Open the application-server administration panel

Click the administration-panel button for the GlassFish or Payara node.

2

Open JDBC Connection Pools

Go to Resources > JDBC > JDBC Connection Pools and click New.

3

Define the pool

Enter a pool name, select javax.sql.DataSource as the resource type, choose the database vendor, and proceed to the next step.

Pool nameA unique identifier, for example MySQLPool.
Resource typejavax.sql.DataSource
Datasource classUse the class supplied by the selected JDBC driver.

Add the database properties required by the selected driver:

serverNameThe database node CNAME or private IP.
portNumberThe listener port, such as 3306 for MySQL.
databaseNameThe application database.
userThe database username.
passwordThe database password.
URLThe JDBC URL when required by the selected data-source class.
jdbc:mysql://node{node_id}-{environment_name}.{hoster_domain}:3306/{database_name}
!

Do not use localhost

The database and application server run in separate containers. Use the database node CNAME, private IP, or attached public IP instead.

4

Test the connection

Save the pool and click Ping. A successful ping confirms that the server can connect with the supplied settings.

Create the JDBC Resource

1

Open JDBC Resources

Go to Resources > JDBC > JDBC Resources and click New.

2

Set the JNDI name

Enter a JNDI name such as jdbc/MyDatabase and select the connection pool created earlier.

3

Save the resource

Confirm the configuration and create the JDBC resource.

Keep names consistent

The JNDI name used by the application must match the configured JDBC resource name.

Use the Resource in an Application

Reference the configured data source through JNDI:

@Resource(lookup = "jdbc/MyDatabase")
private DataSource dataSource;
try (Connection connection = dataSource.getConnection()) {
    // Execute database operations.
}

Expected Result

A GlassFish or Payara JDBC connection pool successfully connects to the selected database. A JDBC resource exposes the pool through a JNDI name, allowing the deployed Java application to reuse managed database connections.

Important Notes

  • Use the database node CNAME or private IP instead of localhost.
  • Confirm that the required JDBC driver is available to GlassFish or Payara.
  • Use javax.sql.DataSource unless another resource type is specifically required.
  • Test the pool with Ping before creating the JDBC resource.
  • Keep the application JNDI name identical to the configured resource name.
  • Store credentials securely and limit database-user privileges.

Common Issues and Solutions

Ping failsCheck the host, port, database name, credentials, driver class, and database-node status.
Driver class is not foundInstall or upload the correct JDBC driver and restart the application-server node when required.
Invalid resource errorConfirm that the JNDI name matches and that the resource points to the correct pool.
Access deniedReview the database user host permissions and granted privileges.
Connections are exhaustedReview maximum pool size, application connection handling, database limits, and connection leaks.