How to use GlassFish Connection Pool in Jelastic

GlassFish provides its Connection Pooling mechanism for resources such as EIS Server, JMS Server and Database Server. Connection Pooling is intended to share server resources among requesting clients.

Let's check out how to setup GlassFish Connection Pool in Jelastic!

Create an Environment

  1. Go to and sign up if you haven't done so yet or log in with your Jelastic credentials by clicking the Sign In link on the page.
  2. Within the Jelastic dashboard, click the Create environment button:

  3. In the Environment Topology dialog, pick GlassFish as your application server and the database you want to use (for example MySQL). Then type your environment name for example, testCP. 

manage glassfish

    It will take just a minute for your environment to be created.

Configure Database

  1. Click the Open in browser button for MySQL.

  2. When you created the environment, Jelastic sent you an email with credentials to the database. Use these credentials to create a user account and the database with the application.

Connection Pool Configuration

1. Upload the MySQL connector to the opt/glassfish3/glassfish/lib directory and restart GlassFish.

2. Open the GlassFish admin page in a web browser.

3. Sign in with the login and password which Jelastic sent to your email.

4. Create a new JDBC Connection Pool. At the first step, type pool name, choose resource type (javax.sql.DataSource), database driver vendor (MySQL) and click on the Next button.

    new pool

5. Then set the connection to your database by typing:

  • user name (your database login)
  • server name (your database host)
  • port number (3306)
  • your database name
  •  password to your database
  • jdbc connection string (URL and Url fields): e.g. jdbc:mysql://{db_host}/

Then click Finish.

    As you can see the Connection Pool is successfully created.

6. Create a new JDBC Resource: type JNDI name, choose pool name and select target (gfcluster).

Connection from Your Java Code

    Put the following code into your Java class: 
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("jdbc/testcp");
    Connection conn = ds.getConnection();

    Now you can deploy your application to Jelastic cloud and enjoy!