Вы находитесь на странице: 1из 9

Table of Contents

1. INTRODUCTION TO JDBC: .............................................................................................................................. 2

1.1 Use of JDBC in WebSphere ...................................................................................................................... 2

1.2 Databases which are supported by WebSphere ..................................................................................... 2

2. REQUIREMENTS: ............................................................................................................................................ 3

3. Target Audience:............................................................................................................................................ 3

4. OVERVIEW: .................................................................................................................................................... 3

4.1 JDBC Resources........................................................................................................................................ 3

4.1.1 J2C alias: ........................................................................................................................................... 4

4.1.2 JDBC Providers .................................................................................................................................. 4

4.1.3 Data Sources ..................................................................................................................................... 4

4.1.4 JNDI (Java Naming and Directory Interface) ..................................................................................... 4

5. Steps for Connecting DB2 with WebSphere: ................................................................................................. 5

5.1 Creating J2C alias ..................................................................................................................................... 5

5.2 Creating a JDBC Providers........................................................................................................................ 6

5.3 Creating a DataSource ............................................................................................................................. 7

In the Install New Application Screen after clicking on next we have to supply the location where the
application which we want to deploy and click on finish after that we need to start the application .. Error!
Bookmark not defined.

After the application got started we need to send the request like ............... Error! Bookmark not defined.

6. Reference Article from Web: ........................................................................... Error! Bookmark not defined.

http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.jpafep.multiplatform.doc/in
fo/ae/ae/cdat_jdbcprov.html.......................................................................... Error! Bookmark not defined.

1
1. INTRODUCTION TO JDBC:

Java database connectivity (JDBC) is a Java specification of a standard Application


Programming Interface (API) that allows java programs to access the database
management System.

The JDBC API consists of set of interfaces and classes written in Java programming
language.

1.1 Use of JDBC in WebSphere

When an application is developed for interacting with the database without the use of
WebSphere we follow some steps those are

1) Loading the Driver

2) Establishing the Connection

3) Executing Statements

4) Getting results

5) Closing Connection

In these 5 process Establishing Connection is a Time taking process as most of the web or
enterprise application use Stateless protocol so once if we establish a connection with the
database with a connection object it is used at that particular transaction for other
transaction at some other point of time we need to again follow all the above 5 steps.

But in WebSphere the application retrieves a DataSource object from JNDI naming space.
After the DataSource object is obtained, the application code calls the getConnection()
request on the data source to get the connection object. After the usage the connection is
not destroyed it is returned to WAS connection pool. Hence the connection is obtained
from pool of connection which are predefined in the WebSphere

1.2 Databases which are supported by WebSphere

 DB2
 ORACLE
 Sybase
 Informix@
 SQL Server

2
IBM Cloudscape and IBM Derby (test and development only)

2. REQUIREMENTS:

To configure JDBC in Web sphere Application Server, the following are needed:

Operating System: AIX (or) Linux (or) Windows

Web Sphere Application Server V7.0

Standalone application server Profile

3. Target Audience:

This document is benefited for System Administrators, Developers and Architects.

4. OVERVIEW:

4.1 JDBC Resources

JDBC resources are created at a specific scope level. The datasource scope level is
inherited from the JDBC provider. For example, if we create a JDBC provider at the node

3
level and then create a data source using that JDBC provider, the data source inherits the
JDBC provider settings, such as classpath, implementation class.

4.1.1 J2C alias:

If a database has security enabled, which is the case for most RDBMS, we will need to
somehow provide the username and password for the connection. By creating a J2C alias,
we can create an authentication resource independent from the provider and data source.
Using this approach, we can change the alias if the database username and password are
changed without reconfiguring the provider or data source. This is a key concept and
WebSphere provides levels of abstraction to allow the configuration of resources
independent form each other. So, in a way, you could say that the JDBC Provider, data
source, and J2C alias are loosely-coupled.

4.1.2 JDBC Providers


It is a database provided by the vendor which database we have to use like oracle, SQL
Server, DB2.This details given by the client or vendor You associate a data source with a
JDBC provider. A data source provides the connection to the RDBMS The JDBC
provider and the data source provide connectivity to a database

4.1.3 Data Sources

When a Data Source object is registered with a JNDI naming service, an application can
retrieve it from the naming service and use it to make a connection to the data source that
it represents. Information about the data source and how to locate it, such as its name, the
server on which it resides, its port number, and so on, is stored in the form of properties
on the DataSource object. Storing this information in this manner makes an application
more portable because it does not need to hard code a driver name, which often includes
the name of a particular vendor. It also makes maintaining the code easier because if, for
example, the data source is moved to a different server, all that needs to be done is to
update the relevant property in the data source. None of the code using that data source
needs to be touched

4.1.4 JNDI (Java Naming and Directory Interface)

The Java Naming and Directory Interface (JNDI) is employed to make applications
more portable. JNDI is essentially an API for a directory service which allows Java
applications to look up data and objects via a name. JNDI is a lookup service where each
resource can be given a unique name. Naming operations, such as lookups and binds, are
performed on contexts. All naming operations begin with obtaining an initial context.
You can view the initial context as a starting point in the namespace. Applications use
JNDI lookups to find a resource using a known naming convention. Administrators can
override the resource the application is actually connecting to without requiring a

4
reconfiguration or code change in the application. This level of abstraction using JNDI is
fundamental and required for the proper use of WebSphere by applications.

5. Steps for Connecting DB2 with WebSphere:


5.1 Creating J2C alias

To create a j2c alias first log into the admin console in the welcome screen we need to
navigate to Security section which is at the left hand side and click on Global Security

Security-->Global Security

In the Global Security Screen click on Java Authentication and Authorization service then
we will get 3 options now select J2C Authentication Data

Global Security-->Java Authentication and Authorization-->J2C alias

In the Global Security Screen after selecting J2C authentication data, Click on 'NEW' to J2C
authentication alias

On the next we will be having 4 fields to enter those are

1) Alias:

2) User ID:

3) Password:

4) Description:

5
NOTE: Alias, UserID, Password fields are mandatory and we need to give db2 instance
name for UserID and Password should be db2 instance Password

Now J2C Alias has been created

5.2 Creating a JDBC Providers

After creating a J2C alias we need to create a JDBC provider which helps us to connect
out application to a particular Database

So click on Resources from the welcome screen which is at the left side from there
select JDBC

After that select JDBC Providers

Then we will be prompted a JDBC Providers Screen

In the next Screen select the scope (Where scope refers to a node of an appserver as
"Node=rwasNode04, Server=server1")

Now click on 'NEW' to create a JDBC Provider

Resources-->JDBC-->JDBC Providers-->NEW

Now Create a new JDBC Provider screen asks for the classpath information for some .jar
files (db2jcc.jar,db2jcc_license_cu.jar,db2jcc_license_cisuz.jar)
6
By default these jar files will be in <DB2 Home>/java/

The native library path will be the <DB2 Home>

Now click on next we will be prompted to Create a new JDBC Provider screen with all
the settings which we have applied for creating a JDBC Provider

Once review them and then click on Finish

Now a DB2 Universal JDBC Driver Provider is been created for a particular node

5.3 Creating a DataSource

To create a DataSource first we need to click on Resources then we need to click on


JDBC next we need to select Data Sources from the welcome screen which is at left side

Resources-->JDBC-->Data-source

In the Create Data Source screen we have to select the scope for the datasource and then
we need to select 'NEW' for creating a new DataSource

NOTE: select the same scope which is been selected while creating a JDBC Provider

After clicking on new we are prompted with a screen which asks for some basic data
source information

1) Data Source Name

2) JNDI name

NOTE: we need to provide both the values (its mandatory)

Next we asked to select a JDBC provider as we have created a DB2 JDBC Universal
Provider no need to create it again so we can select it from the existing

Click on next in create a data source screen


7
In the create a data source screen now we asked to fill some details such as

1) Driver Type: There will be 4 type of drivers we basically select Type 4 driver

2) Database Name: We need to specify the Database name of the instance

3) Server Name: We need to mention the host machine name where the DB2 is
started

4) Port Number: we need to mention the port no of the instance where the db2 is
started

Then Click on next

In the same Screen we are asked for setting up security aliases

We need to select the j2c alias which we have created in the starting

And click on 'NEXT'

In the next Screen we will shown all the setting which we have given while creating a
Datasource review it once and then click on 'FINISH'

Now a DataSoure is been created now we need to test the connection to check whether
the given settings are correct or not

So we need to select the Datasource and then we need to click on Test Connection

8
After the connection operation has been successed go to welcome screen and select
applications options

Вам также может понравиться