3.
Creating a Data Source
The first step to creating a data source in WebSphere is to make
sure the server is running and then login to the administrative
console. A quick and easy way to do this from MyEclipse Blue is
to right-click on the server in the
Servers view, and select
Open Admin Console:
This will automatically open a browser and take you to the admin
console login page. By default, unless you have setup a special
account for WebSphere, you can simply click the
Log in button to enter the admin console with no
further credentials:
Once you are in the admin console, you will want to navigate down
to the
Resources > JDBC > Data sources preference
node, once there you will want to make sure to select an
appropriate scope for the new data source to exist in:
NOTE:
Your scope is simply a specification of how
"visible" you want this data source to be. Just to a
single server, to an entire node, etc.
Once you have selected the scope of the data source,
click the
New button to add a new data source to that
scope.
You will then be prompted to name the data source (for display
purposes in the admin console) as well as provide a JNDI name
that the data source will be bound to (and what you will use to
look it back up inside your projects to use it, for example, in
an EJB 3 project):
Click
Next when done. You are actually done (that's
it!) creating your data source, but the problem is that your data
source doesn't expose any useful connection as a resource. The
wizard will now walk you through that portion of setting up a
JDBC provider that is exposed by this data source.
NOTE:
You can actually setup a JDBC provider and then a data
source mapped to it as separate steps. We are setting up both in
a single wizard in this tutorial.
Now WebSphere is going to prompt you for information about the
JDBC provider you want to associate with this data source. Frist
you need to select the JDBC provider to use to access the
resource. In our case we are going to setup a new Derby
connection back to the MyEclipse Derby Server, so we select
Create new JDBC provider:
After hitting
Next, WebSphere asks for the additional details
about this JDBC provider, we select:
-
Database type: Derby, because we are using the
MyEclipse Derby Server.
-
Provider type: Derby Network Server Using Derby
Client, because we don't want to use the embedded driver, we
want to actually connect remotely as a client to the MyEclipse
Derby Server.
-
Implementation type: Connection pool data
source, because we want WebSphere to manage a pool of
connections for this JDBC source to improve performance.
The remaining
Name and
Description are filled in for us, so we can
click
Next:
Now WebSphere wants to know the exact name of the database in
Derby that we will be connecting to. In our case we can find this
information out by editing the default Derby connection that
comes preconfigured in MyEclipse, when we do that we see the
connection string used, which includes the DB name at the end:
So we see the DB name is
myeclipse, so we enter that in the WebSphere
wizard and click
Next:
WebSphere now shows us a summary of the new data source we setup,
we can review it and when done click
Finish.
As with all changes to WebSphere, you are given a chance of a
review of the changes before publishing them to the master
configuration file for the server and activating the changes.
We are comfortable with our changes, so we need to click
Save to commit these changes to the master
configuration and have them go live inside of our server:
After those changes have been published, we need to test our data
source to make sure it's working.
NOTE: At this point
you need to make sure that the MyEclipse Derby Server is running
inside of MyEclipse, otherwise it will deny the incoming
connection from WebSphere.
To test the connection we check our new
MyEclipse Derby Data Source (or whatever you
named it) and click the
Test connection button:
If the connection is successful, at the top of the admin console
you will see a message similar to the one below saying so:
If for any reason the connection failed, you will first want to
flip back to MyEclipse and make sure that the MyEclipse Derby
Server is running:
If it is running, you will want to edit your data source
connection properties and make sure you got the database name
correct as well as other connection information. It's also
possible if you changed the MyEclipse Derby Server instance to
run on another port besides the default 1527 that the data source
will not be able to connect without customization to it's
connection settings.
|