Question

This page says I can put "clientProgramName" as one of the connection parameters and it will show up on db2 as the correlation ID.

And I quote:

In a java.util.Properties value in the info parameter of a DriverManager.getConnection call.

We're using z/OS. The z/OS version of DB2 seems a lot more limited in terms of this kind of stuff.

Setting the client program name in the params hash of the connect call seems to have no effect, and when I put it on the end of the connect string url like this (which it also says I can do):

jdbc:db2://localhost:5036/DBNAME:clientProgramName=myprog

I get this error:

[jcc][10165][10051][4.11.77] Invalid database URL syntax: 
jdbc:db2://localhost:5036/DBNAME:clientProgramName=myprog. 
ERRORCODE=-4461, SQLSTATE=42815 

Is there any way to send a custom user string to a z/OS db2 server so that connection can be identified on the server?

Was it helpful?

Solution

Depending on the method you use to connect to DB2, you use:

Class.forName

Class.forName("com.ibm.db2.jcc.DB2Driver");
Properties props = new Properties();
props.put("user", "scott");
props.put("password", "tiger");
props.put("clientProgramName", "My Program 1");
Connection conn = DriverManager.getConnection(
    "jdbc:db2://localhost:50000/sample", props);

DataSource

Connection conn = null;
DB2SimpleDataSource ds = new com.ibm.db2.jcc.DB2SimpleDataSource();
ds.setDriverType(4);
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("sample");
ds.setUser("scott");
ds.setPassword("tiger");
ds.setClientProgramName("My Application 2");
conn = ds.getConnection();

I wrote a blog about that: http://angocadb2.blogspot.fr/2012/12/nombre-de-la-conexion-java-en-db2-java.html (Use your favorite translator because it is in Spanish)

OTHER TIPS

According to this page on Info Center, there should be a function on the DB2Connection interface that allows you to change your application identifier, setDB2ClientApplicationInformation (I can't link directly, because there is no anchor, just search for that name).

You can pull the current application ID using the CURRENT CLIENT_APPLNAME special register:

SELECT CURRENT CLIENT_APPLNAME FROM SYSIBM.SYSDUMMY1

There are some other ways to set that register listed on the Info Center link listed above, including the WLM_SET_CLIENT_INFO function.

I am no DB2 expert, but I am looking at a trace record, generated by DB2 for z/OS, that contains a "correlation ID" (field QWHCCV in the product section correlation header of the trace record) that matches the value I set using setClientProgramName (method of the DB2 data source in my Java application).

My Java application is similar to the "DataSource" example given by AngocA, which is similar to the code quoted in the IBM technote 'The name of a DB2 JDBC application appears as "db2jcc_application". How to change it?'. This Java application, running on my Windows PC, connects to DB2 for z/OS. It also - and this is important, depending on which DB2 traces you have started (discussed below) - actually does something after connecting. For example:

pstmt=conn.prepareStatement("SELECT ... ");
rset=pstmt.executeQuery();

When you say, regarding the first example given by AngocA, "it doesn't do anything": what did you hope to see? Exactly where are you looking, what are you looking for, and what method (or tool) are you using to look for it?

For example, if you are looking for SMF type 100, 101, or 102 records (generated by DB2 traces) containing QWHCCV field values that match your correlation ID, then (with apologies if this is the bleeding obvious, teaching you how to suck eggs), on DB2 for z/OS, you need to start the DB2 traces (using the DB2 command START TRACE) that generate those records. Otherwise, there will be nothing to see ("it doesn't do anything"). Note that not all DB2 trace records generated by an application (such as the Java application described above) will contain your correlation ID; prior to a certain point in processing, the correlation ID of such records will have a different value (but that is getting off-topic, and anyway is about as far as I am comfortable describing).

Warning: Experiment with starting DB2 traces on a "sandbox" (development or test) DB2 system, not a production DB2 system. DB2 traces can result in large volumes of data.

You will also see the correlation ID in the message text of some DB2 V10 messages (such as DSNL027I) after "THREAD-INFO=".

For me I had to add a semicolon after each connection parameter.

EX for your case: jdbc:db2://localhost:5036/DBNAME:clientProgramName=myprog;

EX with multiple params: jdbc:db2://localhost:5036/DBNAME:clientProgramName=myprog;enableSysplexWLB=true;blah=true;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top