title: Is there a way to set APPL_NAME on the DB2 Connection externally instead of "db2jcc_application" (e.g. with System Property)
body: <p>I am using a Java application that connects to DB2 over JDBC. It creates the connection such that the application name (sysibmadm.applications -> APPL_NAME) remains the JDBC default "db2jcc_application". Is there a way to <strong>externally</strong> set the APPL_NAME to a desired value? (e.g. in Oracle, I can pass <code>-Doracle.jdbc.v$session.program=MyApplName</code> to have a similar effect).</p>
  
  <p>I want to do this so that I can clearly identify all the connections coming into my DB2. Currently all the java applications show up as "db2jcc_application". </p>
  
  <p>I wrote a small piece of code to illustrate this ...</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.util.Properties;
  
  public class DB2ApplName {
      public static void main(String[] args) throws ClassNotFoundException, SQLException, InterruptedException {
          Class.forName("com.ibm.db2.jcc.DB2Driver");
  
          Properties connProps = new Properties();
          connProps.put("user", "&lt;my db2 user&gt;");
          connProps.put("password", "&lt;my db2 password&gt;");
  
          // Create a connection **WITHOUT** Application Name
          Connection connWithoutApplName = DriverManager.getConnection("jdbc:db2://&lt;ip&gt;:&lt;port&gt;/&lt;dbname&gt;",
                                                                       connProps);
  
          // Add Application Name to the properties
          connProps.put("clientProgramName", "MyApplName");
          // Create a connection **WITH** Application Name
          Connection connWithApplName = DriverManager.getConnection("jdbc:db2://&lt;ip&gt;:&lt;port&gt;/&lt;dbname&gt;",
                                                                    connProps);
          System.out.println("Sleeping for 60 seconds - check the connections.");
          Thread.sleep(60000L); // During this time I will run query on DB2 to see connection details.
  
          connWithoutApplName.close();
          connWithApplName.close();
      }
  }
  </code></pre>
  
  <p>This code creates two connections, one <strong>wihtout</strong> ApplName set and one <strong>with</strong> ApplName set.</p>
  
  <p>When the code is in <code>Thread.sleep</code>, I query the db ...</p>
  
  <pre><code>select appl_name from sysibmadm.applications
  where client_nname = '&lt;my client ip&gt;' with ur;
  
  APPL_NAME         
  ------------------
  db2jcc_application
  MyApplName        
  </code></pre>
  
  <p>As you can see the second connection has the application name correctly stamped, but the first connection simply has "db2jcc_application" as its name. But, of course, I could do this only if I could modify the application code - which I cannot.</p>
  
  <p>The second way I found I can do this is by setting the JDBC URL in the application settings/properties in a particular fashion. Instead of simply using <code>JDBCURL=jdbc:db2://&lt;ip&gt;:&lt;port&gt;/&lt;dbname&gt;</code> in the application settings, if I set <code>JDBCURL=jdbc:db2://&lt;ip&gt;:&lt;port&gt;/&lt;dbname&gt;:clientProgramName=MyApplName;</code>, then the application name gets stamped correctly. Unfortunately, for certain applications that we have, we need to start multiple JVM processes, but I cannot set the above mentioned setting separately for each of these processes. I can set JVM parameters (such as <code>-D</code> parameters) separately for each process.</p>
  
  <p>Thus, I am looking to see if there is a way to <strong>externally</strong> pass the Application Name so that the JDBC Driver will pick it up and stamp it on the connection.</p>