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.
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.
- Download the Platform Independent "JDBC Driver for MySQL" from https://www.mysql.com/products/connector/
- copy mysql-connector-java.jar into the domain1/lib directory of your payara server.
- Restart the payara server.
- Create a new JDBC Connection Pool.
- Right-click on the server in netbeans, and choose Admin console.
- Expand Resources -> JDBC
- Click on "JDBC Connection Pools" and click "New...".
- Fill out the General Settings fields
- Name can be anything
- Resource Type: javax.sql.DataSource
- Database Driver Vendor: MySql8
- Click Next
- Scroll down to "Additional Properties", select all and click Delete Properties (these are all default values you don't need to make explicit)
- 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
- Click on "JDBC Resources" and click "New..."
- Give the resource a JNDI name that matches the JNDI name in your project's persistence.xml file (e.g. jdbc/my_app)
- Choose the pool you just created from the Pool Name drop down
- Click OK