As defined in the Sun JDBC 2.0 Standard Extension specification, data sources allow you to manage a pool of connections to a database. Using connection pools provides you with the following advantages:
It improves performance. Creating connections is expensive; a data source creates a connection as soon as it is instantiated.
It simplifies resource allocation. Resources are only allocated from the data sources, and not at arbitrary places in the code.
It simplifies connection calls. To get a connection in JDBC 1.0, you would need to call Class.forName() on the class name of the database driver, before making DriverManager calls.
Data sources work as follows:
When a servlet, or other client, wants to use a connection, it looks up a data source by name from a JNDI server.
The data source then returns a connection to the client.
If the data source has no more connections, it may ask the database manager for more connections (as long as it has not exceeded the maximum number of connections).
When the client has finished with the connection, it closes the connection.
The data source then returns the connection to the available pool.
You can configure data sources for WebSphere Application Server V4 and V5 by using the data source page in the server editor.
Setting up a server to test data sources
If you want to test data sources on Websphere Application Server, you may need to do one of the following steps:
Create a WebSphere Server.
In the Server Configuration view, double-click the server. The server editor opens.
Select the Data source tab at the bottom of the editor.
For V5 only: To test data sources at the node level, expand Node Settings. To test data sources at the server level, expand Server Settings.
A JDBC provider for DB2 and for Cloudscape will already be created for you (in the Server Settings section only). In that case, you may skip next step if the predefined JDBC provider satisfies your requirements. Before using the predefined JDBC provider, verify that the Class path field specified in the JDBC provider is the correct class path that contains the database driver. Select the JDBC provider from the JDBC provider list and click Edit to edit the JDBC class path.
Create a JDBC provider. A JDBC provider contains configuration for software that enables Java applications to connect to JDBC-compliant databases.
Beside the JDBC provider list table, click Add. The Create a JDBC Provider wizard opens.
In the Database type list box, select a database type.
In the JDBC provider type list box, select a JDBC provider and click Next.
In the Name field, type the name of the resource provider.
In the Implementation class name field, select or type the Java class name of the JDBC provider implementation.
In the Class path list box, if a driver path does not appear, click the Add Path... or the Add External JARs... button (you do not need to specify a class path if you are using Cloudscape). Type or browse to the path where JAR files containing driver classes are located. Ensure that the class path for the JDBC driver is specified correctly for the installation of DB2 on the machine where you are running WebSphere Application Server.
In the Native path list box, specify a list of paths that forms the location for the resource provider native libraries. Native path entries are separated by using the ENTER key and must not contain path separator characters (such as ';' or ':'). Native paths can contain variable (symbolic) names which you can substitute using a variable map.
Define a data source.
Beside Data sources defined in the JDBC provider selected above list, click Add. The Create a Data Source wizard opens:
Select the type of JDBC provider, for example Cloudscape JDBC Provider 5.0.
Select Version 5.0 data source and click Next.
On the Modify Data Source page, specify the details of the data source that you want to create. For more information about any of the fields on this wizard, select the field and then press F1. Click Next.
On the Modify Resource Properties page, select the resource property you want to modify, for example databaseName.
In the Value field, type the value for this property.
Define resource properties for the data source. If you are setting up a data source for a remote database, specify the database-specific information, such as PortNumber and URL, by adding a resource property.
Beside Resource properties defined in the data source selected above list, click Add. The Add a resource property dialog box opens:
In the Name field, type the name associated with this property, such as PortNumber or ConnectionURL.
In the Type field, type the fully qualified Java type of this property, such as java.lang.Integer or java.lang.Byte.
In the Value field, type the value associated with this property in this property set.
In the Description field, type the text to describe any bounds or well-defined values for this property.
Save and close the server editor.