From my course on Web services at Concordia University's Continuing Education Computer Institute. This presentation shows how to configure GlassFish 4.0 with MySQL 5.6 for use in NetBeans 8.0.
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Cejv659 week09 glassfish-s14
1. Java IV: Web Services
Development
CEJV659
Configuring Glassfish for MySQL
2. REST, JPA, NetBeans and GlassFish
NetBeans provides wizards for creating RESTful CRUD
applications
They can be created from either existing JPA entities or
directly from a database
The wizards create stateless session beans for the web
service
While TomEE supports session beans the wizard
generates code that is not compatible with TomEE
Therefore we need to use the GlassFish server
6/2/2014 2
3. REST, JPA, NetBeans and Glassfish
A second problem is the database support in GlassFish
When installed this server is configured with the Derby
sample database
The purpose of these slides is show how to configure
GlassFish for MySQL and then use the wizards
The database we will use is the single table Aquarium
The goal is to create web services that sample programs
used in Java II and Java III can use
6/2/2014 3
4. MySQL
Before you can configure GlassFish you must have
MySQL running and the database created
Next, you must copy the mysql driver to GlassFish
Download the latest driver from MySQL
For Windows it is now an install (msi) file
When run the driver will be found in
C:Program Files (x86)MySQLMySQL Connector J
Copy mysql-connector-java-5.1.30-bin.jar to
glassfish-install-pathdomainsdomain-namelib
If GlassFish is running then restart the server
6/2/2014 4
5. Configuring Glassfish
Step 1
On the Services tab open Servers and right mouse click
on GlassFish Server 4
Select Start
Once GlassFish is running right mouse click on
GlassFish Server 4 again and click on View Domain
Admin Console
6/2/2014 5
7. Resource and Connection Pool
To work with a database you need to
configure the resource and the pool
Resources provide applications a means
to connect to a database
Connection Pools provide reusable
connections to the database
The application uses a resource to
access the database and the resource
uses the pool to get a connection
We need to create the pool before the
resource
6/2/2014 7
8. JDBC Connection Pool
Select JDBC Connection Pool on the tree and then
select New on the table that appears.
6/2/2014 8
10. JDBC Connection Pool
The next form has been filled out based on the choice of
MySQL as the database
Nothing has to be changed except that you should check
Ping: Enabled
10
11. JDBC Connection Pool
If you scroll down on the form you will come to Additional
Properties
After adding the 4 values click on Finish
6/2/2014 11
12. JDBC Connection Pool
This what you should see
If the Ping was not successful just delete the resource or
even the pool and start over.
12
13. JDBC Resource
A connection pool object will now manage the
connections to the database
Our application needs to request a connection from this
object that is not part of our application
The Java Naming and Directory Interface (JNDI) allows
us to refer to an object that belongs to another process,
such as GlassFish, by a name
A JDBC Resource allows you to assign a JNDI name for
the connection pool you wish to use
When your code uses a JNDI name the object is located
and made available
6/2/2014 13
14. JDBC Resource
From the Common Tasks select JDBC Resources
Click on New
6/2/2014 14
15. JDBC Resource
Now you need to give the resource its JNDI name
It usually begins with a prefix that identifies the type of resource
followed by the name you have chosen such as jdbc/aquarium
Select the pool to associate with the resource from the drop down
Pool Name.
15
16. JDBC Resource
Here is what you should see if you have been successful
You are now ready to use the NetBeans wizards
6/2/2014 16