WAS v8.5 > End-to-end paths > Data access resources

Passing client information to a database

Using a WebSphere Application Server API or trace function, we can pass unique client information about every connection that originates from the same data source. Some databases, such as DB2 , support a data source custom property that triggers the database servers to extract client information from WAS connections. (Consult the database documentation to see whether the product supports this capability and which property the product requires.) Be aware, however, these properties introduces limited functionality in WAS. Consequently, an application server connection manager incurs the following risky behaviors, which can result in the transfer of wrong client information to the database.

Application Server offers two methods of passing client information that provide the necessary connection management flexibility. Either method is used to set client information about some connections and not others, as well as set different client information about different database connections from the same data source.


Results


Example: Setting client information with the setClientInformation(Properties) API.

We can set WAS client information on connections to pass that information to the database with this API.

The following example code calls setClientInformation(Properties) on the com.ibm.websphere.rsadapter.WSConnection object.

import com.ibm.websphere.rsadapter.WSConnection;
.....
try {
   InitialContext ctx = new InitialContext();
   //Perform a naming service lookup to get the DataSource object.
   DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/jdbc/myDS");
  }catch (Exception e) {System.out.println("got an exception during lookup: " + e);}

  WSConnection conn = (WSConnection) ds.getConnection();
  Properties props = new properties();
  props.setProperty(WSConnection.CLIENT_ID, "user123");
  props.setProperty(WSConnection.CLIENT_LOCATION, "127.0.0.1");
  props.setProperty(WSConnection.CLIENT_ACCOUNTING_INFO, "accounting");
  props.setProperty(WSConnection.CLIENT_APPLICATION_NAME, "appname");
  props.setProperty(WSConnection.CLIENT_OTHER_INFO, "cool stuff");
  conn.setClientInformation(props);
  conn.close()

Parameters

props contains the client information to be passed. Possible values are:

Refer to the WSConnection documentation for more details on which client information is passed to the backend database. To reset the client information, call the method with a null parameter.

Exceptions

This API creates an SQL exception if the database issues an exception when setting the data.


Subtopics


+

Search Tips   |   Advanced Search