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:
- Create a Connection.
- Call the java.sql.Connection.setClientInfo method to set any of the client info properties that the database server supports.
- Execute an SQL statement to cause the information to be sent to the database server.
Example
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("clientWorkstation", "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();
}
}
}