Most applications use relational databases to store, organize, and retrieve data. Applications access relational databases through the Java Database Connectivity (JDBC) API.
The following topics are addressed here:
Install a supported database product.
To see the current list of database products supported by GlassFish Server, refer to the Oracle GlassFish Server 3.0.1 Release Notes.
Install a supported JDBC driver for the database product.
For a list of drivers supported by GlassFish Server, see Configuration Specifics for JDBC Drivers.
Make the JDBC driver JAR file accessible to the domain administration server (DAS).
Create the database.
The application provider usually delivers scripts for creating and populating the database.
You are now ready to create a connection pool for the database, and a JDBC resource that points to the connection pool. See To Create a JDBC Connection Pool and To Create a JDBC Resource. The final step is to integrate the JDBC driver into an administrative domain as described in Integrating the JDBC Driver.
GlassFish Server includes an implementation of Java DB (formerly known as Derby), however, you can use any JDBC-compliant database. The database is not started automatically when you start GlassFish Server, so if you have applications that require a database, you need to start Java DB manually by using the local start-database subcommand.
Start the database by using the start-database(1) subcommand.
When the database server starts, or a client connects to it successfully, the following files are created at the location that is specified by the --dbhome option:
The derby.log file contains the database server process log along with its standard output and standard error information.
The database files contain your schema (for example, database tables).
This example starts Derby on the host host1 and port 5001.
asadmin> start-database --dbhost host1 --dbport 5001 --terse=true Starting database in the background. Log redirected to /opt/SUNWappserver/databases/javadb.log. Command start-database executed successfully. |
You can also view the full syntax and options of the subcommand by typing asadmin help start-database at the command line.
Use the local stop-database subcommand to stop Java DB on a specified port. A single host can have multiple database server processes running on different ports.
If necessary, notify users that the database is being stopped.
Stop the database by using the stop-database(1) subcommand.
This example stops Java DB on port 5001 of localhost.
asadmin> stop-database --dbhost=localhost --dbport=5001 onnection obtained for host: localhost, port number 5001. Apache Derby Network Server - 10.2.2.1 - (538595) shutdown at 2008-10-17 23:34:2 7.218 GMT Command stop-database executed successfully. |
For a laptop that roams between networks, you might have trouble shutting down the database. If you start Java DB and then change your IP address, you will not be able to stop Java DB unless you add a specific --dbhost argument. For example, if you run asadmin start-database --dbhost = 0.0.0.0, and then disconnect Ethernet and switch to wifi, you should run a command similar to the following to stop the database:
asadmin stop-database --dbhost localhost
You can also view the full syntax and options of the subcommand by typing asadmin help stop-database at the command line.
The Java DB configuration that is available for use with GlassFish Server includes scripts that can help you use Java DB. The following scripts are available in the as-install/javadb/frameworks/NetworkServer/bin directory:
Script to start the network server
Script to stop the network server
Interactive JDBC scripting tool
Script to view all or part of the DDL for a database
Script to display versioning information about the Java DB environment
Script to execute commands on the NetworkServerControl API
Ensure that the JAVA_HOME environment variable specifies the directory where the JDK is installed.
Set the JAVADB_HOME environment variable to point to the as-install/derby directory.
For more information about these utilities, see the following documentation: