Configure data sources

Data sources

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:

Data sources work as follows:

  1. When a servlet, or other client, wants to use a connection, it looks up a data source by name from a JNDI server.

  2. The data source then returns a connection to the client.

  3. 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).

  4. When the client has finished with the connection, it closes the connection.

  5. 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:

  1. Create a WebSphere Server.

  2. In the Server Configuration view, double-click the server. The server editor opens.

  3. Select the Data source tab at the bottom of the editor.

    Data source tab

  4. 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.

  5. 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.

    Edit JDBC provider

  6. Create a JDBC provider. A JDBC provider contains configuration for software that enables Java applications to connect to JDBC-compliant databases.

    1. Beside the JDBC provider list table, click Add. The Create a JDBC Provider wizard opens.

    2. In the Database type list box, select a database type.

      Database type

    3. In the JDBC provider type list box, select a JDBC provider and click Next.

    4. In the Name field, type the name of the resource provider.

    5. In the Implementation class name field, select or type the Java class name of the JDBC provider implementation.

    6. 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.

    7. 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.

      Database Name

    8. Click Finish.

  7. Define a data source.

    1. Beside Data sources defined in the JDBC provider selected above list, click Add. The Create a Data Source wizard opens:

      Data Source Dialog

    2. Select the type of JDBC provider, for example Cloudscape JDBC Provider 5.0.

    3. Select Version 5.0 data source and click Next.

    4. 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.

      Modify Data Source

    5. On the Modify Resource Properties page, select the resource property you want to modify, for example databaseName.

    6. In the Value field, type the value for this property.

      Modify Resource Properties

      Click Finish.

  8. 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.

    1. Beside Resource properties defined in the data source selected above list, click Add. The Add a resource property dialog box opens:

      Add a resource property

    2. In the Name field, type the name associated with this property, such as PortNumber or ConnectionURL.

    3. In the Type field, type the fully qualified Java type of this property, such as java.lang.Integer or java.lang.Byte.

    4. In the Value field, type the value associated with this property in this property set.

    5. In the Description field, type the text to describe any bounds or well-defined values for this property.

    6. Click OK.

  9. Data Source

    Save and close the server editor.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine