3 Advanced Features : Using Client Information

Using Client Information
NOTE: All drivers except for the Salesforce driver support storing and retrieving client information.
Many databases allow applications to store client information associated with a connection. For example, the following types of information can be useful for database administration and monitoring purposes:
■
■
User ID for whom the application using the connection is performing work. The user ID may be different than the user ID that was used to establish the connection.
■
■
■
NOTE: Oracle allows you to store additional client information including the action associated with the current module, identifying information about the client, and the name of the current module.
For DB2 V9.5 and V9.7 for Linux/UNIX/Windows and DB2 for z/OS, this information can feed directly into the Workload Manager (WLM) for workload management and monitoring purposes. See “DB2 Workload Manager (WLM) Attributes” for more information about using the WLM.
How Databases Store Client Information
Typically, databases that support storing client information do so by providing a register, a variable, or a column in a system table in which the information is stored. If an application attempts to store information and the database does not provide a mechanism for storing that information, the driver caches the information locally. Similarly, if an application returns client information and the database does not provide a mechanism for storing that information, the driver returns the locally cached value.
For example, let’s assume that the following code returns a pooled connection to a DB2 V9.1 for Linux/UNIX/Windows database and sets a client application name for that connection. In this example, the application sets the application name SALES157 using the driver property ApplicationName.
// Get Database Connection
Connection con = DriverManager.getConnection(
   "jdbc:datadirect:db2://server1:50000;DatabaseName=jdbc;
   ApplicationName=SALES157","TEST","secret");
...
The application name SALES157 is stored by the DB2 database in the CURRENT CLIENT_APPLNAME register, the location that DB2 reserves for this information. When the connection to the database is closed, the connection is returned to the connection pool as usual and the client information on the connection is reset to an empty string. If we used this same scenario against a MySQL database, which does not support storing client information, the driver would store the application name locally.
Storing Client Information
Your application can store client information associated with a connection using any of the following methods:
■
Using the driver connection properties listed in Table 3-1. This table lists the connection properties your application can use to store client information and where that client information is stored for each database. See the individual driver chapters for a detailed description of each property. See Chapter 2 “Using the Drivers” for information about specifying connection properties using a URL or a JDBC data source.
■
●
●
Connection.setClientInfo(property_name, value)
Refer to Chapter 1 “JDBC Support” in the DataDirect Connect Series for JDBC Reference for more information about these JDBC methods.
■
Using the JDBC extension methods provided in the com.ddtek.jdbc.extensions package. Refer to Chapter 2 “JDBC Extensions” in the DataDirect Connect Series for JDBC Reference for more information about the com.ddtek.jdbc.extensions package.
Additional information that may be used for accounting or troubleshooting purposes, such as an accounting ID
CURRENT CLIENT_ACCTNG register (DB2 for Linux/UNIX/Windows) or CLIENT ACCTNG register (DB2 for z/OS and DB2 for iSeries).
Progress OpenEdge
Microsoft SQL Server
The current action (Select, Insert, Update, or Delete, for example) within the current module
Progress OpenEdge
Microsoft SQL Server
Name of the application currently using the connection
CURRENT CLIENT_APPLNAME register (DB2 for Linux/UNIX/Windows) or CLIENT APPLNAME register (DB2 for z/OS and DB2 for iSeries). For DB2 V9.1 and higher for Linux/UNIX/Windows, it is also stored in the APPL_NAME column in the SYSIBMADM.APPLICATIONS table.
dbms_session value. In addition, it is also stored in the PROGRAM column in the V$SESSION table.
Progress OpenEdge
Microsoft SQL Server
For Microsoft SQL Server 2000 and higher, program_name column in the sysprocesses table. For Microsoft SQL Server 7, local cache.
Host name of the client on which the application using the connection is running
CURRENT CLIENT_WRKSTNNAME register (DB2 for Linux/UNIX/Windows) or CLIENT WRKSTNNAME register (DB2 for z/OS and DB2 for iSeries).
Progress OpenEdge
Microsoft SQL Server
For Microsoft SQL Server 2000 and higher, hostname column in the sysprocesses table. For Microsoft SQL Server 7, local cache.
Additional information about the client to be stored in the database
For Oracle9i R1 (9.1) and higher, the CLIENT_IDENTIFIER column in the V$SESSION table.
Progress OpenEdge
Microsoft SQL Server
User ID for whom the application using the connection is performing work
CURRENT CLIENT_USERID register (DB2 for Linux/UNIX/Windows) or CLIENT USERID register (DB2 for z/OS and DB2 for iSeries).
Progress OpenEdge
Microsoft SQL Server
Driver name and version on the client
CLIENT_PRDID value. For DB2 V9.1 and higher for Linux/UNIX/Windows, it is located in the SYSIBMADM.APPLICATIONS table.
Progress OpenEdge
Microsoft SQL Server
For Microsoft SQL Server 2000 and higher, the hostprocess column in the sysprocesses table. For Microsoft SQL Server 7, local cache.
The module name to be stored in the database
Progress OpenEdge
Microsoft SQL Server
Returning Client Information
Your application can return client information in the following ways:
■
●
●
●
Refer to Chapter 1 “JDBC Support” in the DataDirect Connect Series for JDBC Reference for more information about these JDBC methods.
■
Using the JDBC extension methods provided in the com.ddtek.jdbc.extensions package. Refer to Chapter 2 “JDBC Extensions” in the DataDirect Connect Series for JDBC Reference for more information about the com.ddtek.jdbc.extensions package.
Returning MetaData About Client Information Locations
You may want to return metadata about the register, variable, or column in which the database stores client information. For example, you may want to determine the maximum length allowed for a client information value before you store that information. If your application attempts to set a client information value that exceeds the maximum length allowed by the database, that value is truncated and the driver generates a warning. Determining the maximum length of the value beforehand can avoid this situation.
To return metadata about client information, call the DatabaseMetaData.getClientInfoProperties() method:
// Get Database Connection
Connection con = DriverManager.getConnection(
   "jdbc:datadirect:db2://server1:50000;DatabaseName=jdbc", "test", "secret");
DatabaseMetaData metaData = con.getMetaData();
ResultSet rs = metaData.getClientInfoProperties();
...
The driver returns a result set that provides the following information for each client information property supported by the database:
■
■
■
■
DB2 Workload Manager (WLM) Attributes
The Workload Manager (WLM) is a priority and resource manager within DB2 V9.5 and V9.7 for Linux/UNIX/Windows. On z/OS, the WLM is part of the operating system. When you set client information using the drivers, the WLM can access and use that information for workload management and monitoring purposes as described in Chapter 4 “DB2 Driver”.
DB2 V9.5 and V9.7 for Linux/UNIX/Windows
Table 3-2 lists the WLM attributes for DB2 V9.5 and V9.7 for Linux/UNIX/Windows that map to information set by driver properties. Refer to your DB2 documentation for information about using these WLM attributes.
Additional information that may be used for accounting or troubleshooting purposes, such as an accounting ID
DB2 for z/OS
Table 3-3 lists the WLM attributes for DB2 for z/OS that map to information set by driver properties. Refer to your DB2 documentation for information about using these WLM attributes.
Additional information that may be used for accounting or troubleshooting purposes, such as an accounting ID
User ID for whom the application using the connection is performing work.