The DepartmentDataTest class shows how to access the DEPARTMENT table. This class, which was generated by pureQuery, shows the annotated-method style of programming.
You can create a Java stored procedure from the refactored newAnnotStatic method. The myPdqProperties.put("pdq.executionMode", "STATIC"); statement in this method would cause the stored procedure that you create from the method to run statically.
package ANNOTATED;
// Imports
import java.util.Iterator;
import pureQuery.example.SampleUtil;
import com.ibm.pdq.runtime.Data;
import com.ibm.pdq.runtime.ResultIterator;
import com.ibm.pdq.runtime.factory.DataFactory;
import java.sql.*;
public class DepartmentDataTest {
public static void newAnnotStatic(String[] s) throws SQLException,Exception {
Connection con = DriverManager.getConnection("jdbc:default:connection");
java.util.Properties myPdqProperties = new java.util.Properties();
myPdqProperties.put("pdq.executionMode", "STATIC");
DepartmentData d = DataFactory.getData(DepartmentData.class,
con,myPdqProperties);
Iterator<Department> departments = d.getDepartments();
if(departments.hasNext()){
Department dept = departments.next();
s[0] = dept.getDeptname();
}
}
/**
* @param args
*/
public static void main(String[] args) {
DepartmentData data = null;
try {
if (args.length < 1) {
SampleUtil.println("All required arguments were not provided.");
return;
}
data = SampleUtil.getData(
DepartmentData.class,
"jdbc:db2://iicriollo3.svl.ibm.com:50000/SAMPLE:retrieveMessagesFromServerOnGetMessage=true;",
"db2admin", args[0]);
((Data) data).setAutoCommit(false);
Iterator<Department> getDepartments = data.getDepartments();
Department bean = null;
if (getDepartments.hasNext()) {
bean = getDepartments.next();
((ResultIterator<Department>) getDepartments).close();
} else {
SampleUtil.println("Result set is empty.");
((Data) data).rollback();
return;
}
getDepartments = data.getDepartments();
SampleUtil.println("Results for getDepartments()");
SampleUtil.printAll(getDepartments);
Department getDepartment = null;
((Data) data).commit();
} catch (Exception exp) {
SampleUtil.println(exp.getMessage());
SampleUtil.println(exp.toString());
if (data != null)
((Data) data).rollback();
} finally {
if (data != null)
((Data) data).close();
}
}
}
}