The Pet Catalog application is a Java EE 6 sample that demonstrates usage of
JavaServer Faces 2.0 and the Java Persistence API. Setup instructions here
assume that you are using the following software components:
In the Services window (Ctrl-5; ⌘-5 on Mac), right-click the Databases
node and choose Register MySQL Server.
In the MySQL Server Properties dialog, under the Basic Properties tab, you
can see the default settings for the MySQL server installation. These are:
Server Host Name:localhost
Server Port Number:3306
Administrator User Name:root
Select the Save Password option.
Click OK. The IDE connects to your MySQL database server, and lists database
instances that are maintained by the server.
Create a Database Instance
Right-click the MySQL Server node and choose Create Database.
In the dialog that displays, type in petcatalog. Select the
'Grant Full Access to' option, then select from
the drop-down field.
Click OK. When you do so, an empty database named petcatalog is
created, and a connection to the database is automatically established.
Connections are displayed in the Services window using a connection node (
Create database tables and populate them with sample data
In the Projects window, expand the Server Resources node and double-click
catalog.sql to open it in the IDE's editor.
In the Connection drop-down above the editor, select the
jdbc:mysql://localhost:3306/petcatalog connection that you
created in the previous step.
Click the Run SQL (
) button in the editor's toolbar. The script runs on your MySQL server.
Configuring a Connection Pool and JDBC Resource on GlassFish
The sun-resources.xml file, included in the sample application, is a
GlassFish-specific deployment descriptor.* If
you open the file in the editor (from the Projects window, Server Resources >
sun-resources.xml), you can see that the file instructs the GlassFish
server to create a connection pool named petCatalogPool using the
'root' / 'nbuser' combination and jdbc:mysql://localhost:3306/petcatalog
connection you configured in the previous steps:
* The sun-resources.xml file is not included
in the sample application bundled with IDE versions 6.8 and 6.9. To create the file,
perform the following steps.
Open the Files window (Ctrl-2; ⌘-2 on Mac).
Create a new folder in the PetCatalog project named setup.
To do so, right-click the project node and choose New > Folder. (If Folder is
not displayed, choose Other. Select the Other category, then select the Folder file
type. Click Next.)
Copy (Ctrl-C; ⌘-C on Mac) the sun-resources.xml file from the
location on your computer, then paste (Ctrl-V; ⌘-V on Mac) it into the setup
Switch to the Projects window (Ctrl-1; ⌘-1 on Mac) and note that the
sun-resources.xml file is displayed in the Server Resources node
within the project.
Running the Sample Application
In the Services window, expand the Servers > GlassFish Server 3 node and
choose Properties. In the Servers window that displays, make sure the 'Enable
JDBC Driver Deployment' option is selected. This option will ensure that the
is deployed to GlassFish when your project is deployed. (If the server is already
running, you'll need to restart the server.)
In the Projects window, right-click the PetCatalog project node
and choose Run. The project is compiled, packaged and deployed to GlassFish.
The deployed application then opens in your default browser.