Setting up a server to test data sources for an enterprise application targeted for a WAS
Use the WebSphere® Application Server Deployment editor to define data sources for a specific application for a remote or local WAS.
Prerequisite
- Create an enterprise application and target the server to a WAS v6.0, or later.
To test your data sources on a WAS, complete the following steps:
- Switch to the Java™ EE perspective.
- The location of the WAS Deployment editor depends on the specification-level of your enterprise application project:
- If your enterprise application (EAR) project is at 1.2, 1.3 or 1.4 specification-level, complete the following steps:
- In the Enterprise Explorer view, expand your enterprise application project folder.
- Under the enterprise application project folder for which you want add or edit server configurations, double-click the
Deployment Descriptor to open the Application Deployment Descriptor editor.
- Select the
Deployment tab at the bottom of the editor.
Restriction: Before adding or removing J2EE modules, using the
Module page in the Application Deployment Descriptor editor, first click the
Deployment tab to activate the functions in the deployment page. Then add or remove your modules from the Module page. You need to complete this task for each Application Deployment Descriptor editor session that you want to add or remove modules from the Module page.
- If your enterprise application (EAR) project is at 5.0 specification-level, complete the following steps:
- In the Enterprise Explorer view, right-click your enterprise application project folder.
- Select
Java EE | Open WAS Deployment.
- Expand the Data Source section.
- A JDBC provider for IBM® Cloudscape® (also known as Derby) will already be created for you. In that case, you may skip the below step if the predefined JDBC provider satisfies your requirements. Before using the predefined JDBC provider, verify that the
Class path field specified in the Modify a JDBC Provider wizard is the correct class path that contains the database driver. You can complete this by selecting the JDBC provider from the JDBC provider list and click
Edit to view or 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.
Table 1. Examples of different JDBC providers JDBC Driver Types Example of resource provider IBM DB2® DB2 Universal JDBC Driver Provider Oracle Oracle JDBC Driver Sybase Sybase JDBC 2 Driver - In the
Name field, type the name of the resource provider.
- In the
Implementation class name list, select or type the Java class name of the JDBC provider implementation.
Table 2. Examples of different Java class names of the JDBC provider implementation JDBC Provider Types Example of Java class name DB2 com.ibm.db2.jcc.DB2ConnectionPoolDataSource Oracle oracle.jdbc.pool.OracleConnectionPoolDataSource Sybase com.sybase.jdbc2.jdbc.SybConnectionPoolDataSource - In the
Class path list box, if a driver path does not appear, click the
Add Path or the
Add External JARs button. 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 WAS.
Table 3. Examples of different JAR files containing driver classes JDBC Driver Types Example of JAR files containing driver classes DB2 ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar
${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar
${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar
Oracle ${ORACLE_JDBC_DRIVER_PATH}/ojdbc14.jar Sybase ${SYBASE_JDBC_DRIVER_PATH}/jconn2.jar
Tip: By default, the Class path list box specifies WebSphere environment entries, such as ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar, make sure that you assign ${DB2UNIVERSAL_JDBC_DRIVER_PATH} a value in the Substitution Variables section. For example, create a substitution variable where DB2UNIVERSAL_JDBC_DRIVER_PATH = c:\Program Files\SQLLIB\java(or your system dependent value). For details on how to create a substitution variable, see the Adding substitution variables to an enterprise application targeted for WAS topic.
Alternatively, in the Class path list box you can manually remove the WebSphere environment entries and add new entries with full file paths, such as c:\Program Files\SQLLIB\java\db2jcc.jar
- 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.
- Click Finish.
- Define a data source and resource properties. Beside
Data sources defined in the JDBC provider selected above list, click
Add.
- The Create Data Source wizard opens.
- Select the type of JDBC provider, for example DB2 Universal JDBC Driver Provider.
- Specify a data source for WAS version 5.0 or version 4.0. If your application uses an Enterprise JavaBean (EJB) 1.1 or a java Servlet 2.2 module, select Version 4.0 data source. Click Next.
Note: Due to a limitation in the WAS, the Universal Test Client can only view detailed information for Version 4.0 data sources. Although Version 5.0 data sources are still visible in the JNDI Explorer, you are not able to view their details.
- Specify the following details of the data source that you want to create and then click Next:
- Name (Required)
- Specifies the display name for the data source.
- JNDI name (Required)
- The required Java Naming and Directory Interface (JNDI) name for the resource, including any naming subcontexts. The name is used to link the platform binding information. The binding associates the resources defined the deployment descriptor of the module to the actual (physical) resources bound into JNDI by the platform.
- Example for DB2: jdbc/Sample
- Example for Oracle: jdbc/OracleSample
- Example for Sybase: jdbc/sybase
- Description
- A brief description of the resource.
- Category
- A category string that can be used to classify or group the resource.
- Statement cache size
- The maximum number of prepared statements to cache for the data source. The limit is shared among all connections.
- Data source helper class name
- The datastore helper is used to perform database-specific functions. This is used by the Relational Resource Adapter at run time. The default DataStoreHelper implementation class is set based on the JDBC driver implementation class. For example, if the JDBC provider is DB2, then the default DataStoreHelper class is com.ibm.websphere.rsadapter.DB2DataStoreHelper.
- Connection timeout
- A positive integer specifying the maximum number of seconds that requests for a connection is going to wait if the maximum number of connections is reached and all connections are in use.
- Maximum connections
- The maximum number of physical connections that can be created in this pool.
- Minimum connections
- The minimum number of physical connections that should be maintained.
- Reap time
- Interval in seconds between runs of the pool maintenance thread. The Reap Timeout interval affects the accuracy of the Unused Timeout and Aged Timeout settings. The smaller the interval, the greater the accuracy.
- Unused timeout
- Interval in seconds after which an unused or idle connection is discarded. Unused Timeout should be set higher than Reap Timeout for optimal performance.
- Aged timeout
- Interval in seconds before a physical connection is discarded.
- Purge policy
- Specifies how to purge connections when a stale connection or fatal connection error is detected.
- Component-managed authentication alias
- The alias used for database authentication at run time.
If your database (for example, Cloudscape) does not support user ID and password, then do not set the alias in the component-managed authentication alias or container-managed authentication alias fields. Otherwise, you see the warning message in the system log to indicate that the user and password are not valid properties. (This message is only a warning message; the data source is still created successfully.)
If you do not set an alias (component-managed or otherwise), and your database requires the user ID and password to get a connection, then you receive an exception during run time.
- Container-managed authentication alias
- Specifies authentication data (a string path converted to userid and password) for container-managed sign-on to the resource.
- Use this data source in container managed persistence (CMP) check box
- In Java EE, container-managed persistence (CMP) is a data transfer between an entity bean and a resource manager managed by the entity bean's container. The persistence in the Java EE development environment is delegated to an enterprise bean's container, as opposed to being managed by the bean itself.
- On the Create Resource Properties page, select the resource property you want to modify, for example databaseName.
- In the
Value field, type the value for this property, for example, sample for the database name.
Table 4. Examples of different resource properties databaseName Value DB2 database_name Oracle database_name Derby c:\temp\database_name
- Save and close the server editor. The data source entries has been added to the deployment descriptor files.
Note: If you are using the Type 4 JDBC driver for Oracle, define the URL resource property with the value jdbc:oracle:thin:@ server_name :1521: database_name.