Tags

JDBC Resources in GlassFish and PayaraServer

Note that these instructions work for Payara as well, which is based on GlassFish.

Please submit a ServiceRequest if you would like a database for your application. The computer group will setup the database and provide you with a username, password, and suggested jdbc resource an pool names.

Introduction

Simply put, a JDBC resource is a database. Java applications running in GlassFish use a JDBC resource as their back end database. However, rather than just storing a configuration file with settings for a specific database, Java apps can have the GlassFish container handle the database connection.

The GlassFish container holds database connection information in the connection pool. The GlassFish container holds a JDBC Resource that references the connection pool. The Java app holds a reference to the JDBC Resource. The JDBC Resource is referenced by a JNDI Name, which is just a string.

The Java application is configured to use a specific JDBC resource. The GlassFish container holds all of the connection information such as server, user, and password. Different GlassFish containers can hold different connection information, but all use the same JDBC Resource in order to allow an application to move from one container to another without having to change database connection information in the app.

Creating new database connection.

  1. Download the Platform Independent "JDBC Driver for MySQL" from https://www.mysql.com/products/connector/
  2. copy mysql-connector-java.jar into the domain1/lib directory of your payara server.
  3. Restart the payara server.
  4. Create a new JDBC Connection Pool.
    1. Right-click on the server in netbeans, and choose Admin console.
    2. Expand Resources -> JDBC
    3. Click on "JDBC Connection Pools" and click "New...".
    4. Fill out the General Settings fields
      1. Name can be anything
      2. Resource Type: javax.sql.DataSource
      3. Database Driver Vendor: MySql8
    5. Click Next
    6. Scroll down to "Additional Properties", select all and click Delete Properties (these are all default values you don't need to make explicit)
    7. Really only need four properties:
      • ServerTimezone = America/New_York
      • User = your mysql user
      • Password = your mysql user's password
      • Url = jdbc:mysql://testdb.classe.cornell.edu/3306/database_name
  5. Click on "JDBC Resources" and click "New..."
    1. Give the resource a JNDI name that matches the JNDI name in your project's persistence.xml file (e.g. jdbc/my_app)
    2. Choose the pool you just created from the Pool Name drop down
    3. Click OK
Topic revision: r6 - 09 Jun 2021, DevinBougie
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CLASSE Wiki? Send feedback