Providing Extended Client Information To The Data Source With Client Info Properties - IBM DB2 Manual

Table of Contents

Advertisement

public class ClientInfoTest {
}
Figure 20. Example of passing extended client information to a DB2 server
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.
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.
To set client info properties, follow these steps:
1. Create a Connection.
2. Call the java.sql.setClientInfo method to set any of the client info properties
3. Execute an SQL statement to cause the information to be sent to the database
The following code performs the previous steps to pass a user name and a
workstation name to the DB2 server. The numbers to the right of selected
statements correspond to the previously-described steps.
62
Application Programming Guide and Reference for Java
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,
user, password);
if (conn instanceof DB2Connection) {
DB2Connection db2conn = (DB2Connection) conn;
db2conn.setDB2ClientUser("Michael L Thompson");
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();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
that the database server supports.
server.
1
2
3
4

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents