Loading a Db2 for z/OS table by using an IBM Data Server Driver for JDBC and SQLJ method
The DB2Connection.zLoad method lets you load a Db2 for z/OS table from a Java application.
Procedure
To load a Db2 for z/OS from a Java application, follow these steps:
Examples
Example: Use a LOAD statement from a variable to load data from file customer.data into table MYID.CUSTOMER_DATA.
The numbers to the right of statements correspond to the previously described steps.
import java.sql.*; // JDBC base
import com.ibm.db2.jcc.*; // IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
...
DB2Connection db2conn = (DB2Connection)con; 1
String loadstmt = "TEMPLATE SORTIN DSN &JO..&ST..SORTIN.T&TIME. " + 2
"UNIT SYSVIO SPACE(10,10) CYL DISP(NEW,DELETE,DELETE) " +
"TEMPLATE SORTOUT DSN &JO..&ST..SORTOUT.T&TIME. UNIT SYSVIO " +
"SPACE(10,10) CYL DISP(NEW,DELETE,DELETE) LOAD DATA INDDN " +
"SYSCLIEN WORKDDN(SORTIN) REPLACE PREFORMAT LOG(NO) REUSE " +
"NOCOPYPEND FORMAT DELIMITED UNICODE " +
"INTO TABLE MYID.CUSTOMER_DATA NUMRECS 30000";
// LOAD statement text is
// in a string
String dataFilename = "C:\\customer.data";
// Name of the file that contains
// the input data
String utilid = "ZLOADTEST1";
// Identifier for this run of the
// LOAD utility
LoadResult lr = db2conn.zLoad(loadstmt, dataFilename, utilid); 3
int returnCode = lr.getReturnCode(); 4
String loadMessage = lr.getMessage();
Example: Use a LOAD statement from a file to load data from file customer.data into table MYID.CUSTOMER_DATA.
The numbers to the right of statements correspond to the previously described steps.
import java.sql.*; // JDBC base
import com.ibm.db2.jcc.*; // IBM Data Server Driver for JDBC
// and SQLJ implementation of JDBC
...
DB2Connection db2conn = (DB2Connection)con; 1
String loadstmtOrFile="C:\\Program Files\\IBM\\SQLLIB\\loadStatement.txt"; 2
// Name of the file that contains
// the LOAD statement
Boolean isLoadstmtInFile=true;
// Indicate that the LOAD statement
// is in a file
String dataFilename="C:\\Customer.delimiter.large”;
// Name of the file that contains
// the input data
String utilid="ZLOADTEST2”;
// Identifier for this run of the
// LOAD utility
LoadResult lr =
db2conn.zLoad(loadstmtOrFile, isLoadstmtInFile, filename, utilid); 3
int returnCode = lr.getReturnCode(); 4
String loadMessage = lr.getMessage();