Properties for the IBM Data Server Driver for JDBC and SQLJ

IBM® Data Server Driver for JDBC and SQLJ properties define how the connection to a particular data source should be made. Most properties can be set for a DataSource object or for a Connection object.

IBM Data Server Driver for JDBC and SQLJ property names are case-sensitive.

Methods for setting the properties

Properties can be set in one of the following ways:
  • Using setXXX methods, where XXX is the unqualified property name, with the first character capitalized.
    Properties are applicable to the following IBM Data Server Driver for JDBC and SQLJ-specific implementations that inherit from com.ibm.db2.jcc.DB2BaseDataSource:
    • com.ibm.db2.jcc.DB2SimpleDataSource
    • com.ibm.db2.jcc.DB2ConnectionPoolDataSource
    • com.ibm.db2.jcc.DB2XADataSource
  • In a java.util.Properties value in the info parameter of a DriverManager.getConnection call.
  • In a java.lang.String value in the url parameter of a DriverManager.getConnection call.

    If you specify a property name that does not exist, the IBM Data Server Driver for JDBC and SQLJ does nothing with the property setting, and does not issue an error.

    Some properties with an int data type have predefined constant field values. You must resolve constant field values to their integer values before you can use those values in the url parameter. For example, you cannot use com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL in a url parameter. However, you can build a URL string that includes com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL, and assign the URL string to a String variable. Then you can use the String variable in the url parameter:
        String url = 
         "jdbc:db2://sysmvs1.stl.ibm.com:5021/STLEC1" +
         ":user=dbadm;password=dbadm;" +
         "traceLevel=" +
         (com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL) + ";";
    
         Connection con = 
           java.sql.DriverManager.getConnection(url);
    

Priorities of property settings

If a property is set by multiple methods, the following priority rules apply to the settings:

  • If a db2.jcc.override.property global configuration property is set in the IBM Data Server Driver for JDBC and SQLJ configuration properties file, that setting has the highest priority, and overrides all other settings.
  • If property is set on a DataSource or Connection instance, it has the next highest priority. Settings on a DataSource or Connection instance have equal priority with each other.
  • Global configuration property db2.jcc.property is set when the driver is loaded, and has the lowest priority.

Examples of setting a property

To set property sslKeyStoreLocation, use one of the following methods:

  • Set the property on a DataSource instance.
    Suppose that ds is defined as a DataSource instance, and String variable ksloc contains the keystore location. You can set the keystore location on the ds instance like this:
    ds.setSslKeyStoreLocation(ksloc);
  • Set the property on a Connection instance.
    Suppose that con is defined as a Connection instance, String variable url is the Connection URL, and you want to set the keystore location to /a/b/c. You can set the keystore location and create the Connection instance like this:
    String url = 
         "jdbc:db2://sysmvs1.stl.ibm.com:5021/STLEC1" +
         ":user=dbadm;password=dbadm;" +
         "sslKeyStoreLocation=" + 
         "/a/b/c" +
         ";";
    
         Connection con = java.sql.DriverManager.getConnection(url);
    
  • Set the property in the IBM Data Server Driver for JDBC and SQLJ configuration properties file.
    You can set the property like this, to override all other settings of sslKeyStoreLocation:
    db2.jcc.override.sslKeyStoreLocation=/a/b/c
    Alternatively, you can set the property so that all other settings of sslKeyStoreLocation override it:
    db2.jcc.sslKeyStoreLocation=/a/b/c