Java and Db2 API, Application Program Interface
Part Three - Challenge #08

Background:

Java and Db2 relational database table

JDBC stands for Java Database Connectivity.

JDBC is a Java API to connect and execute relational data base SQL queries.

JDBC API uses JDBC drivers to connect with the database.


Challenge Situation

You will compile and execute Java source to SELECT data from a Db2 for z/OS table. A Java source code issue requires identification and modification to successfully execute.


Challenge Description

You are given Java source code using SQL to SELECT data records from a Db2 table. The Java source code loads a JDBC driver to connect to a Db2 data source. A Java JDBC url is embedded in the code with all the necessary information to establish a connection.

A Db2 connection problem occurs during execution. STDERR identifies the connection problem.

A Java source code modification to the embedded JDBC url is required to successfully connect.


Challenge:

Copy Java source coded to your Unix directory
  • From ISPF Command Shell panel =6,
    enter oput 'zos.mtm2019.public.p3.source(db2java)' 'db2java.java'

Submit JCL to compile and execute the Java program
  • From ISPF Command Shell panel =6,
    enter sub 'zos.public.jcl(db2java)' ; =sd ; st

Review the db2java JCL job output
  • From SDSF enter ? to the left of db2java JCL job output
  • STDERR DDNAME output includes description of the error
    Continue to scoll to right to see the entire message by pressing f11 or entering right
  • What is 'invalid'?

Modify, compile, and execute the DB2JAVA program
  • From ISPF, enter TSO OEDIT
    A list of Unix files appears
  • Select s file db2java.java
  • Remember what was 'invalid'?
    Look through the Java code to find it and fix it
  • Once db2java.java source code is modified, then enter save
  • Enter tso sub 'zos.public.jcl(db2java)' ; =sd ; st
  • View member #08 in P3.OUTPUT for valid SQL result set

What did you just learn?
Java drivers exist to connect to data sources such as Db2 for z/OS.

Next: Challenge #09