DB2 10.5 for Linux, UNIX, and Windows

Providing extended client information to the data source with client info properties

The IBM® Data Server Driver for JDBC and SQLJ version 4.0 supports JDBC 4.0 client info properties, which you can use to provide extra information about the client to the server. This information can be used for accounting, workload management, or debugging.

About this task

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

The application can also use the Connection.getClientInfo method to retrieve client information from the database server, or execute the DatabaseMetaData.getClientInfoProperties method to determine which client information the driver supports.

The JDBC 4.0 client info properties should be used instead IBM Data Server Driver for JDBC and SQLJ-only methods, which are deprecated.

Procedure

To set client info properties, follow these steps:

  1. Create a Connection.
  2. Call the java.sql.Connection.setClientInfo method to set any of the client info properties that the database server supports.
  3. Execute an SQL statement to cause the information to be sent to the database server.

Example

The following code performs the previous steps to pass a client's user name and host 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); 
      conn.setClientInfo("ClientUser", "Michael L Thompson");  2 
      conn.setClientInfo("ClientHostname", "sjwkstn1");
      // Execute SQL to force extended client information to be sent
      // to the server
      conn.prepareStatement("SELECT * FROM SYSIBM.SYSDUMMY1"
         + "WHERE 0 = 1").executeQuery();                      3 
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
}