DB2 Version 9.7 for Linux, UNIX, and Windows

Providing extended client information to the data source with IBM Data Server Driver for JDBC and SQLJ-only methods

A set of IBM® Data Server Driver for JDBC and SQLJ-only methods provide extra information about the client to the server. This information can be used for accounting, workload management, or debugging.

Extended client information is sent to the database server when the application performs an action that accesses the server, such as executing SQL.

In the IBM Data Server Driver for JDBC and SQLJ version 4.0 or later, the IBM Data Server Driver for JDBC and SQLJ-only methods are deprecated. You should use java.sql.Connection.setClientInfo instead.

The IBM Data Server Driver for JDBC and SQLJ-only methods are listed in the following table.

Table 1. Methods that provide client information to the data server
Method Information provided
setDB2ClientAccountingInformation Accounting information
setDB2ClientApplicationInformation Name of the application that is working with a connection
setDB2ClientDebugInfo The CLIENT DEBUGINFO connection attribute for the Unified debugger
setDB2ClientProgramId A caller-specified string that helps the caller identify which program is associated with a particular SQL statement. setDB2ClientProgramId does not apply to DB2® for Linux, UNIX, and Windows data servers.
setDB2ClientUser User name for a connection
setDB2ClientWorkstation Client workstation name for a connection

To set the extended client information, follow these steps:

  1. Create a Connection.
  2. Cast the java.sql.Connection object to a com.ibm.db2.jcc.DB2Connection.
  3. Call any of the methods shown in Table 1.
  4. Execute an SQL statement to cause the information to be sent to the data server.
The following code performs the previous steps to pass a user name and a workstation name to the data server. The numbers to the right of selected statements correspond to the previously-described steps.
Figure 1. Example of passing extended client information to a data server
public class ClientInfoTest {
  public static void main(String[] args) {
    String url = "jdbc:db2://sysmvs1.stl.ibm.com:5021/san_jose";
    try {
      Class.forName("com.ibm.db2.jcc.DB2Driver");
      String user = "db2adm"; 
      String password = "db2adm"; 
      Connection conn = DriverManager.getConnection(url,        1 
        user, password); 
      if (conn instanceof DB2Connection) {
        DB2Connection db2conn = (DB2Connection) conn;           2 
        db2conn.setDB2ClientUser("Michael L Thompson");         3 
        db2conn.setDB2ClientWorkstation("sjwkstn1");
        // Execute SQL to force extended client information to be sent
        // to the server
        conn.prepareStatement("SELECT * FROM SYSIBM.SYSDUMMY1"
          + "WHERE 0 = 1").executeQuery();                      4 
      }
    } catch (Throwable e) {
        e.printStackTrace();
      }
  }
}