1. Let's begin
In this quick tutorial we explore how to create JDBC Resource
and Connection Pool using Glassfish/Sun Application Server (8 - 9.1).
If you are new to Glassfish, remember that your default "admin" password
is "adminadmin" and that accessing Administration site is done via port
4848 , like this: http://localhost:4848 . In this tutorial it is assumed
that you successfully logged in, in which case,the following will direct you through
the Web based administration site.
What needs to be done:
- a. First you need to create a Connection Pool and configure it before creating JDBC Resource
- b. Once the Connection Pool is created, you can use a button "PING" - to test the connection
- c. Make sure the Database is actually running and you have correct IP or hostname (check if its pingable)
- d. Make sure that Listener is running on Oracle Server to accept requests and make sure that your Naming Service is configured
1.5
Pre-requisites
Before starting the App Server and attempting to create a Connection Resource to Oracle, You must:
Quick Reference
For your information , here is a nice FAQ from Oracle about JDBC
drivers: JDBC
Faq
If you are using Oracle 8i (8.1.7.0) and up, any 10g JDBC driver will
suit you just fine.
If you are using Oracle 7 or less you should use JDBC driver for 9i.
2. All Ahead
If you want to use Oracle JDBC driver for more than one domain (internal
instances) on Glassfish/Sun Application Server
You can place the JAR file into "glassfish root directory"\lib
For Example: C:\Sun\AppServer\lib
However if you would like it to be used for a certain domain, follow this:
"glassfish root"\domains\"domain name"\lib\ext
For Example: C:\Sun\AppServer\domains\domain1\lib\ext
You need this step since Sun App. Server does not upload Drivers for you
(probably a legal issue)
It knows the driver namespaces and other specifics related to various
databases.
3. Let's dig further
Now we are ready to proceed in creating the Connection Pool
Enter some meaningfull name in "NAME" field. Mind you it is NOT the JNDI
name , but an alias within the Glassfish environment.
Common values for Oracle Connection in General Settings would be as follows
:
DataSource Classname : oracle.jdbc.pool.OracleDataSource
Resource Type: javax.sql.ConnectionPoolDataSource
You might want to CHECK (click the button to validate) the ConnectionA
useful feature of Glassfish
Here is the part where some people like myself failed , hence this tutorial
was born
Click to see Properties and Visual elements of this tutorial.
In the Properties section below you have some properties. Now if your Oracle Server resides on the Solaris (or other UNix) or Linux machine
It looks unappealling but it's a Oracle specific way to denote the Connection. The only important part here is: SERVER=DEDICATED
The rest are just usual properties
Also if you already have a Oracle Client on your Glassfish machine setup, and have a record in TNS (naming service) you could use your alias for the URL instead of specifying host, ports, sid,protocol. Please read on the Naming Services for Oracle Client software.
Now, if you have a Windows machine that your Oracle Database is running on, this would be just fine:
url: jdbc:oracle:thin:@"ip or hostname":1521:"sid" plus username and password
Please do not include the semi-colon ("). Lastly, don't forget to save your changes.
We are done, lets PING this Connection Pool to see if it was successfull.
4. And we're finished
Once the Connection Pool is created, we are pretty much done.
Go to JDBC Resource and create a new JNDI Name and don't forget to select
Pool Name (that you previously created).
Make sure the JDBC Resource is enabled.
You're done.