Java Stored Procedures - Getting the Environment Ready   John Lantz Federal Reserve Board June 11, 2008
Agenda for today <ul><li>What is Java, background information </li></ul><ul><li>Java and DB2 </li></ul><ul><li>Implementin...
Java – why use it? <ul><li>A platform independent object oriented programming language </li></ul><ul><li>Richer programmin...
Java – what is it? <ul><li>You have two options on how to deploy  JDBC  or  SQLJ </li></ul>JDBC Dynamic SQL Easier to writ...
Java – example (JDBC) <ul><li>/** </li></ul><ul><li>* JDBC Stored Procedure M1JPL01.test_java_jdbc </li></ul><ul><li>*/ </...
Java – example (SQLJ) <ul><li>/** </li></ul><ul><li>* SQLJ Stored Procedure M1JPL01.test_java_sqlj </li></ul><ul><li>*/ </...
Java – Which to use? <ul><li>One reason why you use stored procedures is to have code that is efficient as possible </li><...
Tasks for z/OS System Programmer <ul><li>Install JDBC/SQLJ Drivers </li></ul><ul><li>Set up WLM environment </li></ul><ul>...
Installing drivers <ul><li>Part of DB2 base code: FMID JDB8812 </li></ul><ul><li>Jobs DSNDDEF2 and DSNISMKD </li></ul><ul>...
WLM setup… <ul><li>Set up RRS (Resource Recovery Service) </li></ul><ul><li>DESCSTAT=YES in DSNZPARM (necessary for SQLJ s...
WLM setup… (continued) <ul><li>Don’t confuse the WLM environments.  </li></ul><ul><li>In our environment…  DSNUWLM1 and DS...
WLM setup… (continued) <ul><li>Sample DD statements within the Java WLM address space. The JAVAENV specifies the LE run-ti...
UNIX stuff… <ul><li>Set up UNIX environment LIBPATH, CLASSPATH, PATH, etc… (remember some UNIX is case sensitive) </li></u...
Installing / configuring DB2 components <ul><li>DSNTIJSG – creates various stored procedures (grant execute to PUBLIC) SQL...
Installing / configuring DB2 components <ul><li>To use Development Center, must have SELECT on the following tables… SYSIB...
Building a procedure <ul><li>Things the programmer needs to know before building a procedure via the Development Center - ...
 
 
 
Building a procedure (cont) <ul><li>Do not check “Build using DSNTJSPP” on the z/OS Options panel.   This is for the Legac...
 
Java – Define DDL for procedure <ul><li>This gets created for you….   CREATE PROCEDURE  M1JPL01.TEST_JAVA_SQLJ  ( IN  INP_...
Experiences… <ul><li>Still in the exploratory mode.  </li></ul><ul><li>It’s working and available for the developers </li>...
Recommended resources <ul><li>Information Center http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp </li></u...
Upcoming SlideShare
Loading in …5
×

Java Stored Procedures - Getting the Environment Ready

1,112 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,112
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Stored Procedures - Getting the Environment Ready

  1. 1. Java Stored Procedures - Getting the Environment Ready John Lantz Federal Reserve Board June 11, 2008
  2. 2. Agenda for today <ul><li>What is Java, background information </li></ul><ul><li>Java and DB2 </li></ul><ul><li>Implementing Java on the mainframe </li></ul><ul><li>Building a procedure via Development Center </li></ul><ul><li>Tips, resources, etc… </li></ul>
  3. 3. Java – why use it? <ul><li>A platform independent object oriented programming language </li></ul><ul><li>Richer programming language then SQL Procedure Language </li></ul><ul><li>Compile it once and deploy it anywhere </li></ul>
  4. 4. Java – what is it? <ul><li>You have two options on how to deploy JDBC or SQLJ </li></ul>JDBC Dynamic SQL Easier to write Errors detected at RUN time SQLJ Static SQL Faster run time Stable access paths Errors detected at BIND time Easy monitoring
  5. 5. Java – example (JDBC) <ul><li>/** </li></ul><ul><li>* JDBC Stored Procedure M1JPL01.test_java_jdbc </li></ul><ul><li>*/ </li></ul><ul><li>package PKG80503035400970; </li></ul><ul><li>import java.sql.*; // JDBC classes </li></ul><ul><li>public class Test_java_jdbc </li></ul><ul><li>{ </li></ul><ul><li>public static void test_java_jdbc ( ResultSet[] rs1 ) throws SQLException, Exception </li></ul><ul><li>{ </li></ul><ul><li>// Get connection to the database </li></ul><ul><li>Connection con = DriverManager.getConnection(&quot;jdbc:default:connection&quot;); </li></ul><ul><li>PreparedStatement stmt = null; </li></ul><ul><li>boolean bFlag; </li></ul><ul><li>String sql; </li></ul><ul><li>sql = &quot;SELECT SCHEMA, NAME FROM SYSIBM.SYSROUTINES&quot;; </li></ul><ul><li>stmt = con.prepareStatement( sql ); </li></ul><ul><li>bFlag = stmt.execute(); </li></ul><ul><li>rs1[0] = stmt.getResultSet(); </li></ul><ul><li>} </li></ul>
  6. 6. Java – example (SQLJ) <ul><li>/** </li></ul><ul><li>* SQLJ Stored Procedure M1JPL01.test_java_sqlj </li></ul><ul><li>*/ </li></ul><ul><li>package PKG80503035149340; </li></ul><ul><li>import java.sql.*; // JDBC classes </li></ul><ul><li>import sqlj.runtime.*; </li></ul><ul><li>import sqlj.runtime.ref.*; </li></ul><ul><li>#sql context SPContext; </li></ul><ul><li>#sql iterator Test_java_sqlj_Cursor1 ( String, String ); </li></ul><ul><li>public class Test_java_sqlj </li></ul><ul><li>{ </li></ul><ul><li>public static void test_java_sqlj ( ResultSet[] rs1 ) throws SQLException, Exception </li></ul><ul><li>{ </li></ul><ul><li>Test_java_sqlj_Cursor1 cursor1 = null; </li></ul><ul><li>SPContext ctx = null; </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>ctx = new SPContext( &quot;jdbc:default:connection&quot;, false ); </li></ul><ul><li>#sql [ctx] cursor1 = </li></ul><ul><li>{ SELECT SCHEMA, NAME FROM SYSIBM.SYSROUTINES }; </li></ul><ul><li>rs1[0] = cursor1.getResultSet(); </li></ul><ul><li>} </li></ul><ul><li>catch (SQLException e) </li></ul><ul><li>{ </li></ul><ul><li>// Close open resources </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>if (cursor1 != null) cursor1.close() </li></ul><ul><li>} catch (SQLException e2) { /* ignore */ }; </li></ul><ul><li>throw e; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  7. 7. Java – Which to use? <ul><li>One reason why you use stored procedures is to have code that is efficient as possible </li></ul><ul><li>This is accomplished by static SQL – thus avoiding overhead of prepare/etc… at execution time </li></ul><ul><li>Using JDBC – kind of defeats the purpose of a stored procedure… </li></ul>
  8. 8. Tasks for z/OS System Programmer <ul><li>Install JDBC/SQLJ Drivers </li></ul><ul><li>Set up WLM environment </li></ul><ul><li>Set up UNIX system services </li></ul><ul><li>Required DB2 changes </li></ul>
  9. 9. Installing drivers <ul><li>Part of DB2 base code: FMID JDB8812 </li></ul><ul><li>Jobs DSNDDEF2 and DSNISMKD </li></ul><ul><li>DSNDDEF2 - creates necessary DDDEF for DB2 universal drivers </li></ul><ul><li>DSNISMKD - allocates the HFS structures </li></ul><ul><li>(both jobs are smp/e stuff) </li></ul>
  10. 10. WLM setup… <ul><li>Set up RRS (Resource Recovery Service) </li></ul><ul><li>DESCSTAT=YES in DSNZPARM (necessary for SQLJ support) </li></ul><ul><li>Set NUMTCB=5 for java WLM. Initially set to 1, not to exceed 8. </li></ul><ul><li>Make sure //JAVAENV DD statement is correct </li></ul><ul><li>WLM environment should be dedicated to Java stored procedures (don’t mix COBOL and SQL) </li></ul>
  11. 11. WLM setup… (continued) <ul><li>Don’t confuse the WLM environments. </li></ul><ul><li>In our environment… DSNUWLM1 and DSNUJAV1 </li></ul><ul><li>DSN…WLM1 is used in the build process (issues the refresh command) </li></ul><ul><li>DSN…JAV1 is where the procedures execute (where the procedure executes) </li></ul>
  12. 12. WLM setup… (continued) <ul><li>Sample DD statements within the Java WLM address space. The JAVAENV specifies the LE run-time options for Java routines //JAVAENV DD DSN=SYS2.DB2.DEVU.DSNUJAV1.JSPENV //JAVAERR DD PATH='/usr/lpp/dsnu/jsppuser/JAVAERR.TXT', PATHOPTS=(ORDWR,OCREAT,OAPPEND), PATHMODE=(SIRUSR,SIWUSR,SIRGRP,SIWGRP,SIROTH,SIWOTH) //JAVAOUT DD PATH='/usr/lpp/dsnu/jsppuser/JAVAOUT.TXT', PATHOPTS=(ORDWR,OCREAT,OAPPEND), PATHMODE=(SIRUSR,SIWUSR,SIRGRP,SIWGRP,SIROTH,SIWOTH) </li></ul>
  13. 13. UNIX stuff… <ul><li>Set up UNIX environment LIBPATH, CLASSPATH, PATH, etc… (remember some UNIX is case sensitive) </li></ul><ul><li>DB2_HOME (where JDBC driver is installed) </li></ul><ul><li>JAVA_HOME Per IBM, we must install Java 31-bit version software on the z/OS 1.8 system and the JAVA_HOME must point to the 31 bit Java version. (remember some UNIX is case sensitive) </li></ul>
  14. 14. Installing / configuring DB2 components <ul><li>DSNTIJSG – creates various stored procedures (grant execute to PUBLIC) SQLJ.DB2_INSTALL_JAR, SQLJ.DB2_REPLACE_JAR SQLJ.DB2_REMOVE_JAR SQLJ.DB2_UPDATEJARINFO </li></ul><ul><li>DSNJDBC and DSNJAR collection’s perform GRANT CREATE ON COLLECTION… as necessary </li></ul><ul><li>DSNTIJMS – creates additional indexes and catalog objects (may have been run in V7…, check) </li></ul>
  15. 15. Installing / configuring DB2 components <ul><li>To use Development Center, must have SELECT on the following tables… SYSIBM.SYSDUMMY1 SYSIBM.SYSROUTINES SYSIBM.SYSPARMS SYSIBM.SYSJARCONTENTS SYSIBM.SYSJAROBJECTS SYSIBM.SYSJAVAOPTSDSNTIJSG </li></ul><ul><li>Individual users do not need their own profiles set up within UNIX </li></ul>
  16. 16. Building a procedure <ul><li>Things the programmer needs to know before building a procedure via the Development Center - Proper Java WLM environment - Proper collection to use, and the necessary GRANT CREATE ON COLLECTION… </li></ul>
  17. 20. Building a procedure (cont) <ul><li>Do not check “Build using DSNTJSPP” on the z/OS Options panel. This is for the Legacy Driver type 2, not the Universal Driver type 2. </li></ul>
  18. 22. Java – Define DDL for procedure <ul><li>This gets created for you…. CREATE PROCEDURE M1JPL01.TEST_JAVA_SQLJ ( IN INP_PARM VARCHAR(128) CCSID EBCDIC ) RESULT SETS 1 EXTERNAL NAME M1JPL01.SQL80503035149340:PKG80503035149340.Test_java_sqlj.test_java_sqlj' LANGUAGE JAVA PARAMETER STYLE JAVA NOT DETERMINISTIC NULL CALL FENCED MODIFIES SQL DATA NO DBINFO COLLID DSNJDBC WLM ENVIRONMENT DSNUJAV1 PROGRAM TYPE SUB COMMIT ON RETURN NO ; </li></ul><ul><li>External name refers to java classname.methodname </li></ul>
  19. 23. Experiences… <ul><li>Still in the exploratory mode. </li></ul><ul><li>It’s working and available for the developers </li></ul><ul><li>Performance has been good so far </li></ul>
  20. 24. Recommended resources <ul><li>Information Center http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp </li></ul><ul><li>DB2 for z/OS and OS/390: Ready for Java SG24-6435-00 </li></ul><ul><li>DB2 for z/OS Stored Procedures : Through the CALL and Beyond SG24-7083-00 </li></ul><ul><li>Application Programming Guide and Reference for Java SC18-7414-05 </li></ul>

×