Building Database Applications

If you want to access databases using JDBC, you must compile the appropriate database driver classes. These compiled classes can be built into one or more DLLs, or they can be bound into the application.

To build database applications (where the database driver classes are built into a single DLL):

  1. Issue the following command to compile the driver classes into a compound DLL:

    hpj -jll driverclass

  2. Compile your application.

Example:

In this example, you build a database application using the driver classes provided with a sample application in IBM DB2 v5.0. The driver classes are found in the following zip file (where path is the install path of DB2):

path\sqllib\java\db2java.zip

  1. Build a compound DLL to contain your DB2 components:

    1. Change to the following directory (where path is the install path of DB2):

      path\sqllib\samples\java

    2. Issue the following command to set the classpath:

      set CLASSPATH=g:\sqllib\java\db2java.zip;%CLASSPATH%

    3. Issue the following command to build the compound DLL:

      hpj -jll -o DB2Driver.jll COM.ibm.db2.jdbc.app.DB2Driver

  2. Issue the following command to build the application executable DB2Appl.java that will use the compound DLL:

    hpj -exe DB2Appl.java

Example 2:

If you want to use the JDBC-ODBC bridge with the DB2 sample application, you need to edit the source file and specify JDBC-ODBC instead of the DB2 driver.

  1. Edit the file DB2Appl.java.

  2. Make the following changes:

    Replace: Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
    With: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    Replace: String url = "jdbc:db2:sample";
    With: String url = "jdbc:odbc:sample";

  3. Issue the following command to set the classpath:

    set CLASSPATH=%CLASSPATH%;.

  4. Issue the following command to build an executable:

    hpj -exe DB2Appl.java

 


Building Executables and DLLs