Connecting to a DRDA database server

To connect to a DRDA (DB2 and Oracle) database server, include the application information on the system CLASSPATH.

About this task

To connect to the database, you need add the CLASSPATH to your system. In your application, you need to define the connection string and the connection.

Procedure

  1. Add the CLASSPATH.

    To load the JDBC driver, the Java Virtual Machine requires that the location and name of the driver and Log4j implementation files be included in the system CLASSPATH. For example:

    install_dir/lib/dv-jdbc-[version #].jar
    install_dir/lib/log4j-api-[version #].jar
    install_dir/lib/log4j-core-[version #].jar
    install_dir/lib/

    All jar files in the lib folder must be in the CLASSPATH, and the folder that contains the log4j2.xml file must be in the CLASSPATH.

    On the Windows command line, you can choose to include all files in the install_dir/lib, or you can choose to list each jar file that you want to include. The following example shows how to include all files:

    classpath install_dir/lib/*;install_dir/lib;
    codeph;
    

    On *Nix:

    classpath install_dir/lib/*:install_dir/lib

    To list each jar file individually, rather than using install_dir/lib/*, pass the database connection information to the driver manager in the form of a connection URL. Using the following URL format as an example, you can substitute values that are specific to your database management system:

    jdbc:rs:dv://host-name:port-number[;property=value[;…]]

    Substitute the host-name with the IP address or computer name of the server that hosts the database management system. Substitute the port-number with the TCP/IP port number on which the Data Virtualization Manager server listens for incoming requests. Multiple connection properties must be separated by semicolons.

    Note: On the command line on Windows, if a property value contains a semi-colon, you must enclose the whole connection string in double quotation marks. On *Nix, the same is true for the colon character.
  2. Define the connection string and the connection in your application.

    The JDBC driver uses the JDBC Driver Manager to connect to a database server. To connect to the database management system, use the DriverManager.getConnection() method to pass the connection URL as the argument, as shown in the following example:

    Connection conn = DriverManager.getConnection(
    "jdbc:rs:dv://host-name:port-number;   
    DatabaseType=DRDAorDB2;
    user=user-id;password=user-password;
    subsystem=my-subsystem;
    Charset=CharsetName");
    Note: Different database management systems have different required and optional connection properties. You must understand the DBMS to which you want to connect in order to properly configure the JDBC driver.

    By default, the DatabaseType property is DRDAorDB2, which defaults the subsystem value to NONE. To specify your subsystem, set the value accordingly.

    The Charset must match the SQLENGDFLTCCSID parameter setting of the Data Virtualization Manager server, and it must be compatible with the MCCSID of the target DB2 subsystem.

    To connect to the Data Virtualization Manager server, use the following syntax:

    Connection conn = DriverManager.getConnection(
    "jdbc:rs:dv://host-name:port-number;
    DatabaseType=DVS;
    user=user-id;password=user-password;"
    Charset=CharsetName");
    

    You can use the hashpassword.cmd utility to generate a hashed format of your text password. You can include the hashed password in the connection string or .ini file for your application. The script prompts the user for the plain text password. To avoid prompting, the password can be specified as a command-line argument.

    For information on interface methods, see JDBC driver APIs