Appendices Unit <ul><li>Connecting to External Data Sources – on the i5 </li></ul>Topics:
Topics – Access to Mainframe –  System i and System z  – Data <ul><li>What’s Possible? </li></ul><ul><li>SQL Access </li><...
Options -  Non -Relational Data Access from EGL (COBOLGEN only) <ul><li>System z - from Generated COBOL </li></ul><ul><ul>...
Other Remote Data Access from EGL Debugger and Java Gen Parts <ul><li>QSAM  – sequential files </li></ul><ul><ul><li>AIX, ...
Relational – SQL Data Access from EGL (Java Gen) <ul><li>Control/Specify access to: DB2,Oracle, Derby, MS-SQLServer, etc) ...
Remote Access from EGL – DB2 on z/OS <ul><li>What’s required to make this work? </li></ul><ul><ul><li>IBM Universal JDBC D...
Remote Access from EGL – DB2/400 on i5 <ul><li>Access done through System i Java Toolkit supplied JDBC Driver </li></ul><u...
Getting the JT400 Toolkit for DB2 access – System i  <ul><li>or </li></ul><ul><li>With WDSC, in the following directory </...
Workshop – Connect Your EGLWeb Project to Your i5 DB2/400 Data (Tomcat) <ul><li>Assuming you have all the proper authoriza...
   Specifying Connection Info to Databases – 1 of 4 <ul><li>Use EGL SQL Database Connection Preference …for </li></ul><ul...
   Specifying connection info to Databases – 2 of 4 <ul><li>Select: </li></ul><ul><ul><li>DB2 for i5/OS </li></ul></ul><u...
   Specifying connection info to Databases – 3 of 4 <ul><li>Specify:  </li></ul><ul><ul><li>   Disable filter </li></ul>...
   Specifying connection info to Databases – 4 of 4 <ul><li>Ensure that your new, i5 connection is the default – Click Ap...
Specifying Database Connection – WebSphere <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>sqlJNDI Name in build...
Specifying Database Connection – Tomcat <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>sqlJNDI Name in build de...
Connecting a Tomcat Application Server to an AS/400 Database <ul><li>You will need to do the following, to connect your To...
   Modify Your Project’s context.xml File (add a new Resource for accessing your i5) <ul><li>From Project Explorer: </li>...
   Customize the Project’s BuildFile  <ul><li>From Project Explorer: </li></ul><ul><ul><li>Open  EGLSourceEGLWeb.eglbld <...
   Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables  <ul><li>From Project E...
   Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables  <ul><li>From Define th...
   Create a Page to Access your i5 Data  <ul><li>From Project Explorer: </li></ul><ul><ul><li>Right-click over:  WebConte...
   Create a Page to Access your i5 Data  <ul><li>With your cursor between the get <variableName> statement, </li></ul><ul...
   Create a Page to Access your i5 Data  <ul><li>Add a Where clause – similar to the one shown here </li></ul><ul><ul><li...
   Create a Page to Access your i5 Data  <ul><li>From Page Designer – from Page Data: </li></ul><ul><ul><li>Drag  searchF...
   Create a Page to Access your i5 Data (optional styling) <ul><li>From Page Designer – Properties, with the dataTable se...
   Run the Page – and Search <ul><li>Right-Click over your page, and select:  Run on server </li></ul><ul><li>Enter a val...
Database Connections – Allowing the Data Source to Define the Schema P roblem: You have multiple DB2 environments.  The ta...
Database Connections – Adding Custom Properties to JDBC Drivers P roblem: You need to provide read-only SQL data access to...
Database Connections JT400 – Setting Binary Translation on For CCSID Problems <ul><li>P roblem:  Why are my web pages retu...
Specifying Connection Info to Databases – 4 of 4 <ul><li>For non-J2EE Generated Java Apps  and </li></ul><ul><li>Debug (if...
Adding Jar file to Classpath for JDBC Drivers – 1 of 3 <ul><li>For J2EE Apps: </li></ul><ul><ul><li>WAS JDBC Provider defi...
Adding Jar file to Classpath for JDBC Drivers – 2 of 3 <ul><li>For non-J2EE Generated Java Apps  </li></ul><ul><li>and </l...
Adding Jar file to Classpath for JDBC Drivers – 3 of 3 <ul><li>Debug (if using EGL Preferences) </li></ul><ul><ul><li>Main...
Miscellaneous - SQLRetrieve Preferences for COBOL Gen record  employee  type  SQLRecord  {tableNames = [[&quot;DRBRUCE.EMP...
Available Materials (Access to Remote Resources) <ul><li>Documents on DeveloperWorks: </li></ul><ul><ul><li>DB2Unicon.doc ...
  Lab1 – Configure a Connection for DB2 <ul><li>From  Window  >  </li></ul><ul><li>Preferences  >  </li></ul><ul><li>EGL ...
  Lab2 – Use the Connection in the Data Perspective <ul><li>From Window  </li></ul><ul><li>Open Perspective </li></ul><ul...
   Lab3 – Use the Connection to SQLRetrieve Schema into an EGL Record <ul><li>From the Web Perspective, open CustomerLib....
  Lab4 – Create a Connection From your EAR File to DB2 <ul><li>This is a multi-step/complex lab, where you will create, m...
*** REVIEW *** Specifying Connection Info to Databases <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>JNDI Name...
  1. Add a new JAAS Authentication Entry <ul><li>From Project Explorer: </li></ul><ul><ul><li>Expand  EGLWebEar </li></ul...
  2 Create a new JDBC Provider <ul><li>Continuing on the Deployment tab… </li></ul><ul><ul><li>Scroll up and from Data So...
  3. Create a new JNDI Name for your DB2 Database – 1 of 2 <ul><li>Continuing on the Deployment tab - Select your new JDB...
  3. Create a new JNDI Name for your DB2 Database – 2 of 2 <ul><li>From Create Resource Properties, specify the following...
  4. Add a New SQL Resource Reference to your Project’s web.xml file <ul><li>Add an entry in web.xml for the new JNDI nam...
  5. Create a new EGL Build File for your DB2 Connection <ul><li>As you did in a previous lab in this course, you will cr...
  6. Create a new Page – 1 of 3 <ul><li>From Project Explorer, Right-click over WebContents and create a new Web Page, na...
  6. Create a new Page – 2 of 3 <ul><li>From Page Designer, from the Page Data area </li></ul><ul><li>Select  empArray  –...
  (Optional) 6. Create a new Page – 3 of 3 <ul><li>From Page Designer, with the entire dataTable selected (see Notes***) ...
  7. Specify the New Build File for Your Web Page <ul><li>   Before running your page, you must assign the JSFHandler to...
  Run the Page <ul><li>Right-click over the content area, and select: Run on server  </li></ul><ul><li>Click the triangle...
Upcoming SlideShare
Loading in …5
×

Slide 1

491 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
491
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Note – a JDBC Driver is simply client software that contains connectivity features so that your EGL logic parts can access remote databases. JDBC drivers exist for most (almost all) of the major data sources – including: DB2, Oracle, MS-SQLServer, etc.
  • Note – a JDBC Driver is simply client software that contains connectivity features so that your EGL logic parts can access remote databases. JDBC drivers exist for most (almost all) of the major data sources – including: DB2, Oracle, MS-SQLServer, etc.
  • Notes: The build descriptor’s entry generates the sqlJNDIName into the Java beans (for your EGL Page and its managed bean) It is also possible to enter the information in the Project Ear file (see above) in your Application Server’s specification
  • Notes: The build descriptor’s entry generates the sqlJNDIName into the Java beans (for your EGL Page and its managed bean) It is also possible to enter the information in the Project Ear file (see above) in your Application Server’s specification
  • First thing I usually do is translate &amp;quot;library&amp;quot; to &amp;quot;schema&amp;quot; in my head and it starts to make sense. We normally use unqualified table names and then set the &amp;quot;libraries&amp;quot; property of the JDBC connection to contain library name. This gives us the portability we need between systems and differing library names. You can actually allow for / if you&apos;re using qualified names by setting the &amp;quot;naming&amp;quot; property to &amp;quot;system&amp;quot;. The full list of properties is in the IBM i InfoCenter at: http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzahh/jdbcproperties.htm The other two that are extremely useful are setting trace=true and toolboxTrace=jdbc and you see all the SQL being used by the app - an invaluable tool for debugging. Tomcat resource definition should normally look something like... &lt;Resource type=&amp;quot;com.ibm.as400.access.AS400JDBCDataSource&amp;quot; name=&amp;quot;jdbc/as400DB&amp;quot;/&gt; &lt;ResourceParams name=&amp;quot;jdbc/as400DB&amp;quot;&gt; &lt;parameter&gt;&lt;name&gt;user&lt;/name&gt;&lt;value&gt;MYUSER&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;libraries&lt;/name&gt;&lt;value&gt;MYLIB&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;password&lt;/name&gt;&lt;value&gt;MYPASSWORD&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;serverName&lt;/name&gt;&lt;value&gt;MYSERVER&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;naming&lt;/name&gt;&lt;value&gt;sql&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;trace&lt;/name&gt;&lt;value&gt;false&lt;/value&gt;&lt;/parameter&gt; &lt;parameter&gt;&lt;name&gt;toolboxTrace&lt;/name&gt;&lt;value&gt;jdbc&lt;/value&gt;&lt;/parameter&gt; &lt;/ResourceParams&gt;
  • &lt;Resource driverClassName=&amp;quot;com.ibm.as400.access.AS400JDBCDriver&amp;quot; maxActive=&amp;quot;4&amp;quot; maxIdle=&amp;quot;2&amp;quot; maxWait=&amp;quot;5000&amp;quot; auth=&amp;quot;Container&amp;quot; name=&amp;quot;jdbc/i5&amp;quot; password=“&lt;YourPassWord&gt;&amp;quot; type=&amp;quot;javax.sql.DataSource&amp;quot; url=&amp;quot;jdbc:as400:&lt;YourHostName&gt;;naming=sql;&amp;quot; username=“&lt;YourUserID&gt;&amp;quot; /&gt;
  • Notes: The Schema name is caseSenSitivE You will need to restart the server for this change to your EAR file to take effect
  • Notes: Thanks to Mark Evans and George Silber for this technique
  • Notes: Thanks to Claus Weiss/IBM for this info. Also note that, if the Data Access Wizard has downloaded DataItem properties with HEX(…) DataTypes – you will have to re-factor the DataItems to: char, string, etc.
  • Notes: Copy/Paste record statement – but please realize that you will need to enter your DB2 schema name – not jsayles!!! record employeeDeptJoin type sqlRecord { tablenames=[[&amp;quot;&lt;yourSchema&gt;.Employee&amp;quot;, &amp;quot;E&amp;quot;],[&amp;quot;&lt;yourSchema&gt;.Department&amp;quot;, &amp;quot;D&amp;quot;]] } end
  • Notes: These steps are specific to connecting to DB2 on your local PC. On step 3 above, you can configure for connecting to remote DB2.
  • Notes: The build descriptor’s entry generates the sqlJNDIName into the Java beans (for your EGL Page and its managed bean) It is also possible to enter the information in the Project Ear file (see above) in your Application Server’s specification
  • Notes:
  • Notes:
  • Notes:
  • Notes:
  • Notes: Resource References and JNDI names (like everything else in Java) are case-sensitive !!! Note also that, if you get a database run-time error along the lines of: comp/env /… missing, you need to add a resource entry to web.xml (see slide) of the same name as a matching EAR file JNDI name for a JDBC driver
  • Notes:
  • Notes: package jsfhandlers; //What folder do I live in? import eglderbyr7.data.*; //What files in other folders do I reference? import com.ibm.egl.jsf.*; handler testDB2Page type JSFHandler {onConstructionFunction = onConstruction, view = &amp;quot;testDB2Page.jsp&amp;quot;, viewRootVar = viewRoot} //Global EGL data variables viewRoot UIViewRoot; empArray employeeDeptJoin[0]; //an array of employees function onConstruction() //A custom EGL/SQL function to return data through the join record //Note the where clause - added to avoid a cartesian product result get empArray with #sql{ select E.EMPNO, E.FIRSTNME, E.MIDINIT, E.LASTNAME, E.WORKDEPT, E.PHONENO, E.HIREDATE, E.JOB, E.EDLEVEL, E.SEX, E.BIRTHDATE, E.SALARY, E.BONUS, E.COMM, D.DEPTNO, D.DEPTNAME, D.MGRNO, D.ADMRDEPT, D.LOCATION from jsayles.Employee E, jsayles.Department D where E.workdept = d.Deptno order by D.DEPTNO asc }; end end
  • Notes:
  • Notes: If the entire dataTable is not selected, click in a column of the dataTable, then press the up arrow key on your PC twice to select it
  • Notes:
  • Notes:
  • Slide 1

    1. 1. Appendices Unit <ul><li>Connecting to External Data Sources – on the i5 </li></ul>Topics:
    2. 2. Topics – Access to Mainframe – System i and System z – Data <ul><li>What’s Possible? </li></ul><ul><li>SQL Access </li></ul><ul><ul><li>How to do it? </li></ul></ul><ul><ul><li>Configuration Possibilities </li></ul></ul><ul><ul><li>Specifying Connection Information </li></ul></ul><ul><ul><li>Specifying Jar File Locations </li></ul></ul><ul><ul><li>Miscellaneous </li></ul></ul><ul><li>Access to Files </li></ul><ul><ul><li>Remote </li></ul></ul><ul><ul><li>From Generated COBOL programs </li></ul></ul><ul><li>Lab accessing DB2 </li></ul>Note: Original materials by Mark Evans: - [email_address] EGL Logic Part Data Access System z or IBM i
    3. 3. Options - Non -Relational Data Access from EGL (COBOLGEN only) <ul><li>System z - from Generated COBOL </li></ul><ul><ul><li>Serial files – (QSAM files on the host) </li></ul></ul><ul><ul><li>Indexed, relative keys (VSAM files on the host) </li></ul></ul><ul><ul><li>CICS </li></ul></ul><ul><ul><ul><li>Transient Data Queues </li></ul></ul></ul><ul><ul><ul><li>Temporary Storage Queues </li></ul></ul></ul><ul><ul><ul><li>Spool </li></ul></ul></ul><ul><li>System i - from Generated COBOL </li></ul><ul><ul><li>File Access </li></ul></ul><ul><ul><ul><li>Serial </li></ul></ul></ul><ul><ul><ul><li>Indexed </li></ul></ul></ul><ul><ul><ul><li>Relative Record </li></ul></ul></ul><ul><ul><li>Note: Data Queues are accessible only through called CL programs, not direct. </li></ul></ul>
    4. 4. Other Remote Data Access from EGL Debugger and Java Gen Parts <ul><li>QSAM – sequential files </li></ul><ul><ul><li>AIX, Windows only </li></ul></ul><ul><ul><li>As standard external files, defined as resource associations </li></ul></ul><ul><li>VSAM - Indexed, relative key files </li></ul><ul><ul><ul><li>Uses EGL supplied Distributed File Manager support </li></ul></ul></ul><ul><ul><ul><ul><li>VSAMWIN.zip in plug-in directories </li></ul></ul></ul></ul><ul><ul><ul><li>SNA (or TCP62) based </li></ul></ul></ul><ul><ul><ul><ul><li>Requires SNA client product (like IBM Personal Communications) to supply protocol drivers </li></ul></ul></ul></ul><ul><ul><ul><li>Reference doc: WDz6RemoteVSAM.pdf </li></ul></ul></ul>
    5. 5. Relational – SQL Data Access from EGL (Java Gen) <ul><li>Control/Specify access to: DB2,Oracle, Derby, MS-SQLServer, etc) </li></ul><ul><ul><ul><li>Requires JDBC driver and access to jar/zip file containing the class </li></ul></ul></ul><ul><ul><ul><ul><ul><li>Example: com.ibm.db2.jcc.DB2Driver </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Connect to database via Connection URL </li></ul></ul></ul><ul><ul><ul><ul><ul><li>Example: jdbc:db2://localhost:50000/SAMPLE </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Or, connect to database via JNDI name </li></ul></ul></ul><ul><ul><ul><ul><ul><li>Example: jdbc/sample </li></ul></ul></ul></ul></ul><ul><ul><ul><li>EGL does not know or care that it is connecting to a remote database (System i or System z) It just connects to a </li></ul></ul></ul><ul><ul><ul><ul><li>URL (non-J2EE) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>JNDI name (J2EE) </li></ul></ul></ul></ul>
    6. 6. Remote Access from EGL – DB2 on z/OS <ul><li>What’s required to make this work? </li></ul><ul><ul><li>IBM Universal JDBC Driver + Valid DB2 Connect License Jar ***Notes </li></ul></ul><ul><ul><ul><li>DB2 V8.1 or later </li></ul></ul></ul><ul><ul><ul><li>Just supply access information </li></ul></ul></ul><ul><ul><ul><li>Reference Doc: DB2Unicon.doc </li></ul></ul></ul>DB2 Host Name DB2 Host Port DB2 Location Jar file for Universal Driver License Jar file for Remote z/OS connection
    7. 7. Remote Access from EGL – DB2/400 on i5 <ul><li>Access done through System i Java Toolkit supplied JDBC Driver </li></ul><ul><li>What’s required to make this work? </li></ul><ul><ul><li>JT400.jar </li></ul></ul><ul><ul><li>Valid connection information, authentication and permissions </li></ul></ul><ul><ul><ul><li>IP Address of the host machine </li></ul></ul></ul><ul><ul><ul><li>User ID </li></ul></ul></ul><ul><ul><ul><li>Password </li></ul></ul></ul><ul><ul><ul><li>System or sql schema </li></ul></ul></ul>Host Name of System i machine URL must specify as400 JT400 jar file containing AS400JDBCDriver class
    8. 8. Getting the JT400 Toolkit for DB2 access – System i <ul><li>or </li></ul><ul><li>With WDSC, in the following directory </li></ul><ul><ul><li>In your installation directory </li></ul></ul><ul><li>… or... </li></ul><ul><li>From the System i directories </li></ul><ul><ul><li>QIBMProdDataHTTPPublicj4400lib </li></ul></ul>
    9. 9. Workshop – Connect Your EGLWeb Project to Your i5 DB2/400 Data (Tomcat) <ul><li>Assuming you have all the proper authorizations, you will do the following: </li></ul><ul><ul><li>Create a new connection – to your i5 and DB2400 </li></ul></ul><ul><ul><li>Make this new connection the default connection </li></ul></ul><ul><ul><li>Customize the Tomcat context.xml – to point to your i5 </li></ul></ul><ul><ul><li>Customize the project’s Buildfile with a sqlJNDIname property value that connects to your Tomcat context.xml file’s entry (to point to your i5) </li></ul></ul><ul><ul><li>Run the Data Access Wizard to generate new SQLRecords and Libraries for your i5 DB2 tables </li></ul></ul><ul><ul><li>Create a page that uses the SQLRecords and accesses i5 data </li></ul></ul>
    10. 10.  Specifying Connection Info to Databases – 1 of 4 <ul><li>Use EGL SQL Database Connection Preference …for </li></ul><ul><ul><li>SQL Retrieve </li></ul></ul><ul><ul><li>SQL Statement Validation </li></ul></ul><ul><ul><li>EGL Debugger if not in debug build descriptor </li></ul></ul><ul><li>From Preferences , select: SQL Database Connections </li></ul><ul><li>Click: New… </li></ul>
    11. 11.  Specifying connection info to Databases – 2 of 4 <ul><li>Select: </li></ul><ul><ul><li>DB2 for i5/OS </li></ul></ul><ul><li>Enter the following: </li></ul><ul><li>Hostname, or “ping-able” IP address </li></ul><ul><ul><li>User ID </li></ul></ul><ul><ul><li>Password </li></ul></ul><ul><li>Click: </li></ul><ul><ul><li>T est Connection </li></ul></ul><ul><li>Click </li></ul><ul><ul><li>Next > </li></ul></ul>
    12. 12.  Specifying connection info to Databases – 3 of 4 <ul><li>Specify: </li></ul><ul><ul><li> Disable filter </li></ul></ul><ul><ul><li> Selection </li></ul></ul><ul><li>Check: </li></ul><ul><ul><li>However many libraries you’d like to do development in </li></ul></ul><ul><li>Click: </li></ul><ul><ul><li>F inish </li></ul></ul>
    13. 13.  Specifying connection info to Databases – 4 of 4 <ul><li>Ensure that your new, i5 connection is the default – Click Apply then OK </li></ul>
    14. 14. Specifying Database Connection – WebSphere <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>sqlJNDI Name in build descriptor </li></ul></ul><ul><ul><li>JNDI reference in web.xml </li></ul></ul><ul><ul><li>Project EAR File </li></ul></ul><ul><ul><ul><li>Application Deployment Descriptor </li></ul></ul></ul>DB2
    15. 15. Specifying Database Connection – Tomcat <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>sqlJNDI Name in build descriptor </li></ul></ul><ul><ul><li>context.xml (Resource driverClassname) in WebContentMETA-INF </li></ul></ul>DB2
    16. 16. Connecting a Tomcat Application Server to an AS/400 Database <ul><li>You will need to do the following, to connect your Tomcat Server to an AS/400 Database: </li></ul><ul><li>Add the necessary jdbc client/driver .JAR files to you’re the tomcat: commonlib folder  </li></ul><ul><li>Customize a <Resource … entry in your project’s context.xml </li></ul><ul><li>Here is an example of such a <Resource entry for an AS/400 JDBC driver: </li></ul><ul><li><Resource driverClassName=&quot;com.ibm.as400.access.AS400JDBCDriver&quot; </li></ul><ul><li>maxActive=&quot;4&quot; maxIdle=&quot;2&quot; maxWait=&quot;5000&quot; auth=&quot;Container&quot; </li></ul><ul><li>name=&quot;jdbc/<yourlogicalJNDIname>&quot; password=&quot;xxxxxxx&quot; </li></ul><ul><li>type=&quot;javax.sql.DataSource&quot; </li></ul><ul><li>url=&quot;jdbc:<your connection URL>;naming=system;&quot; </li></ul><ul><li>username=“<your user ID>&quot;/> </li></ul>
    17. 17.  Modify Your Project’s context.xml File (add a new Resource for accessing your i5) <ul><li>From Project Explorer: </li></ul><ul><ul><li>Open WebContentMETA-INF context.xml </li></ul></ul><ul><ul><li>From the Slide *** Notes – copy/paste the sample < Resource driverClassName into the file as shown in the screen capture below. Then modify the: </li></ul></ul><ul><ul><ul><li>name and password: name=“jdbc/i5” password=“your password” </li></ul></ul></ul><ul><ul><ul><li>url (carefully specify your HostName) </li></ul></ul></ul><ul><ul><ul><li>Username: (your user id) </li></ul></ul></ul><ul><ul><li>Save your changes </li></ul></ul>
    18. 18.  Customize the Project’s BuildFile <ul><li>From Project Explorer: </li></ul><ul><ul><li>Open EGLSourceEGLWeb.eglbld </li></ul></ul><ul><ul><li>Click into the sqlJNDIName value (Left-click to edit) </li></ul></ul><ul><ul><li>Change the sqlJNDIName to match your new i5 Resource driverClassName: jdbc/i5 </li></ul></ul><ul><ul><li>Save your changes </li></ul></ul>
    19. 19.  Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables <ul><li>From Project Explorer: </li></ul><ul><ul><li>Right-click over EGLSource </li></ul></ul><ul><ul><li>Select: New > Other > </li></ul></ul><ul><li>From Select a wizard: </li></ul><ul><ul><li>Expand the EGL category </li></ul></ul><ul><ul><li>Select: EGL Data Access Application </li></ul></ul><ul><ul><li>Click: Next > </li></ul></ul><ul><li>From Define project settings: </li></ul><ul><ul><li>Open the Project Name combo-box, and select: EGLWeb </li></ul></ul><ul><ul><li>Open the Database Connection combo-box, and select your new i5 named connection </li></ul></ul><ul><ul><li>Select your tables (not too many?) </li></ul></ul><ul><ul><li>Click Next > </li></ul></ul>
    20. 20.  Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables <ul><li>From Define the Fields </li></ul><ul><ul><li>Choose a key field for each table </li></ul></ul><ul><ul><li>Click: Next > </li></ul></ul><ul><li>From Define project creation options </li></ul><ul><ul><li>Check: Qualify table names with schema </li></ul></ul><ul><ul><li>Click Finish </li></ul></ul>
    21. 21.  Create a Page to Access your i5 Data <ul><li>From Project Explorer: </li></ul><ul><ul><li>Right-click over: WebContent </li></ul></ul><ul><ul><li>Specify: New > Web Page </li></ul></ul><ul><ul><li>Name the page: yourPage. jsp </li></ul></ul><ul><li>Modify the boiler-plate heading text, and edit the EGL </li></ul>Using Content Assist (Ctrl/Spacebar) : Add a string variable named; searchField Add a variable for one of your i5 tables - make it an array [0]; Add a new function, named: searchFunc() In this function, add a get statement, that references the i5 table variable
    22. 22.  Create a Page to Access your i5 Data <ul><li>With your cursor between the get <variableName> statement, </li></ul><ul><ul><li>Right-click </li></ul></ul><ul><ul><li>Select: </li></ul></ul><ul><ul><ul><li>SQL Statement </li></ul></ul></ul><ul><ul><ul><li>Add </li></ul></ul></ul>
    23. 23.  Create a Page to Access your i5 Data <ul><li>Add a Where clause – similar to the one shown here </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><li>where <field> > :searchfield </li></ul></ul><ul><li>Optionally modify the order by clause </li></ul><ul><li>Save your EGL code </li></ul><ul><li>From Project Explorer, </li></ul>Note: colon prefix :searchField <ul><li>Generate your project </li></ul>
    24. 24.  Create a Page to Access your i5 Data <ul><li>From Page Designer – from Page Data: </li></ul><ul><ul><li>Drag searchField onto the page, and create an input field with a single Submit Button </li></ul></ul><ul><ul><li>Drag searchFunc on top of the Submit Button </li></ul></ul><ul><ul><li>Drag the i5 table array variable on to the page to create a JSF dataTable, Select only a few of the columns from your table </li></ul></ul><ul><ul><li>Optionally, drag an HTML Rule between the Submit Button and dataTable </li></ul></ul>
    25. 25.  Create a Page to Access your i5 Data (optional styling) <ul><li>From Page Designer – Properties, with the dataTable selected </li></ul><ul><ul><li>From the hx:dataTable property: Give the dataTable a Border </li></ul></ul><ul><ul><li>From Display options, specify: </li></ul></ul><ul><ul><ul><li>No Column class (for alternate row colors) </li></ul></ul></ul><ul><ul><ul><li>A scrollable area </li></ul></ul></ul>
    26. 26.  Run the Page – and Search <ul><li>Right-Click over your page, and select: Run on server </li></ul><ul><li>Enter a valid search criteria and click the Search button </li></ul>
    27. 27. Database Connections – Allowing the Data Source to Define the Schema P roblem: You have multiple DB2 environments. The tables are named the same across the environments, but the schema name changes. Ex. DB2P.EMP, DB2Q.EMP, DB2T.EMP, etc. How can you pass a different Schema name that qualifies tables in through your dynamic SQL statements? A nswer: You can solve this for each EAR file. 1. From the EAR file’s Application Deployment Descriptor/Deployment tab – find the Data Source, and enter a currentSchema for the DB2 Schema you wish to qualify the tables with 2. When you import the SQL from the Data Access Application Wizard do NOT “qualify table names with schema name” (note this was a checkbox in the wizard) **Notes
    28. 28. Database Connections – Adding Custom Properties to JDBC Drivers P roblem: You need to provide read-only SQL data access to un-committed rows in your database (so-called “dirty read” database access. There is no property for this in your JDBC connections under WAS (the default is to allow access only to “committed” and un-locked rows. A nswer: You can solve this for each Data Source by customizing the Data Source, and adding a Resource Property as follows: 1. From the EAR file’s Application Deployment Descriptor/Deployment tab – find the Data Source, and from the Resource properties defined in the data source selected , click: Add 2. To allow access to uncommitted rows, provide the Name/Type and Value shown in the screen capture 3. To learn more about customizing a DataSource, read the following IBM Document: http://www-1.ibm.com/support/docview.wss?rs=180&uid=swg21224492
    29. 29. Database Connections JT400 – Setting Binary Translation on For CCSID Problems <ul><li>P roblem: Why are my web pages returning hexadecimal characters to my .JSP page or EGL program? </li></ul><ul><li>A nswer: Normally, JT400 driver will translate EBCDIC characters to EGL character data automatically. If it’s sending back hexadecimal values, then it is likely that the field in the DB2/400 database has a CCSID 65535 property. To fix this problem (for web pages): </li></ul><ul><li>From the EAR file’s Application Deployment Descriptor/Deployment tab – find the Data Source, and from the Resource properties defined in the data source selected , </li></ul><ul><ul><li>Scroll down to find the translateBinary property entry </li></ul></ul><ul><ul><li>Click: Edit </li></ul></ul><ul><ul><li>Value: true </li></ul></ul><ul><ul><li>Save your changes to the Deployment Descriptor </li></ul></ul><ul><ul><li>Restart your server </li></ul></ul><ul><li>***Notes </li></ul>
    30. 30. Specifying Connection Info to Databases – 4 of 4 <ul><li>For non-J2EE Generated Java Apps and </li></ul><ul><li>Debug (if not using EGL Preferences) </li></ul><ul><ul><li>In Build descriptor </li></ul></ul><ul><ul><ul><li>sqlDB </li></ul></ul></ul><ul><ul><ul><ul><li>Connection URL </li></ul></ul></ul></ul><ul><ul><ul><li>sqlJDBCDriverClass </li></ul></ul></ul><ul><ul><ul><ul><li>Class to use for connection </li></ul></ul></ul></ul><ul><ul><li>Which results in </li></ul></ul><ul><ul><ul><li>rununit.properties entries  </li></ul></ul></ul><ul><ul><li>Found in JavaSource folder </li></ul></ul>
    31. 31. Adding Jar file to Classpath for JDBC Drivers – 1 of 3 <ul><li>For J2EE Apps: </li></ul><ul><ul><li>WAS JDBC Provider definition plus </li></ul></ul><ul><ul><li>WAS WebSphere Variables </li></ul></ul>
    32. 32. Adding Jar file to Classpath for JDBC Drivers – 2 of 3 <ul><li>For non-J2EE Generated Java Apps </li></ul><ul><li>and </li></ul><ul><li>Debug (if not using EGL Preferences) </li></ul><ul><ul><li>In Java Build Path of Project Properties </li></ul></ul>
    33. 33. Adding Jar file to Classpath for JDBC Drivers – 3 of 3 <ul><li>Debug (if using EGL Preferences) </li></ul><ul><ul><li>Mainly used for customers who are only generating COBOL for deployed apps </li></ul></ul>
    34. 34. Miscellaneous - SQLRetrieve Preferences for COBOL Gen record employee type SQLRecord {tableNames = [[&quot;DRBRUCE.EMPLOYEE&quot;]]} 10 EMPNO char (6) {column=&quot;EMPNO&quot;, isNullable= yes }; 10 FIRSTNME char (12) {column=&quot;FIRSTNME&quot;, isNullable= yes; 10 MIDINIT char (1) {column=&quot;MIDINIT&quot;, isNullable= yes }; 10 LASTNAME char (15) {column=&quot;LASTNAME&quot;, isNullable= yes; 10 HIREDATE char (10) {column=“HIREDATE&quot;, isNullable= yes }; 10 .. record employee type SQLRecord {tableNames = [[&quot;DRBRUCE.EMPLOYEE&quot;]]} EMPNO string {column=&quot;EMPNO&quot;, isNullable= yes , maxLen=6}; FIRSTNME string {column=&quot;FIRSTNME&quot;, isNullable= yes , maxLen=12}; MIDINIT string {column=&quot;MIDINIT&quot;, isNullable= yes , maxLen=1}; LASTNAME string {column=&quot;LASTNAME&quot;, isNullable= yes , maxLen=15}; HIREDATE date {column=“HIREDATE&quot;, isNullable= yes }; Instead of… Produces
    35. 35. Available Materials (Access to Remote Resources) <ul><li>Documents on DeveloperWorks: </li></ul><ul><ul><li>DB2Unicon.doc - database setup for DB2 on z/OS access </li></ul></ul><ul><ul><li>iSeriesTutorial.doc - includes database setup for DB2 on iSeries access </li></ul></ul><ul><ul><li>db2oniSeriesSetup.doc - database setup for DB2 on iSeries </li></ul></ul><ul><ul><li>WDz6RemoteVSAM.pdf - Remote VSAM access to z/OS from EGL </li></ul></ul><ul><ul><li> debugger </li></ul></ul>
    36. 36.  Lab1 – Configure a Connection for DB2 <ul><li>From Window > </li></ul><ul><li>Preferences > </li></ul><ul><li>EGL > </li></ul><ul><li>SQL Database Connection </li></ul><ul><li>Create a new connection, and specify parameters for DB2  </li></ul><ul><li>Note that, if you have DB2 installed locally on your machine, you may use DB2 UDB (You will have to select the proper version)  </li></ul><ul><li>If you wish to use DB2 mainframe (either iSeries or System z), you will need to read through the documentation described on the previous slide (Available Materials) for additional steps and assistance. </li></ul><ul><li>Press Test Connection to test your settings. </li></ul><ul><li>Click Finish </li></ul>
    37. 37.  Lab2 – Use the Connection in the Data Perspective <ul><li>From Window </li></ul><ul><li>Open Perspective </li></ul><ul><li>Other </li></ul><ul><li>Data </li></ul><ul><li>… </li></ul><ul><li>Using your skills from the previous unit in this course, explore a DB2 database using your new Connection </li></ul><ul><li>Here we are showing the SAMPLE DB2 database  </li></ul>
    38. 38.  Lab3 – Use the Connection to SQLRetrieve Schema into an EGL Record <ul><li>From the Web Perspective, open CustomerLib.egl. Scroll to the bottom, and enter the following record statement: </li></ul><ul><li>With your cursor inside the statement, Right-Click and select: SQL Record > Retrieve SQL </li></ul><ul><li>Press Ctrl/S (Save) </li></ul>SAMPLE Database Catalog Read slide Notes*** <ul><li>You will need to enter YOUR schema name – not jsayles </li></ul>
    39. 39.  Lab4 – Create a Connection From your EAR File to DB2 <ul><li>This is a multi-step/complex lab, where you will create, modify or connect all of the system files and DB2 properties discussed in this Appendix. Take your time – and triple-check your work. Once you’ve mastered these steps and concepts you will be able to connect to your own company’s data sources. Here’s what you’ll be doing: </li></ul><ul><ul><li>(One-time step) Customize your project’s EAR file entries: </li></ul></ul><ul><ul><ul><li>Add a new JAAS Authentication Alias – so your pages can login and access DB2 data </li></ul></ul></ul><ul><ul><ul><li>Add a new JDBC Provider to DB2 – specify a logical name that points to your DB2 client/connectivity software </li></ul></ul></ul><ul><ul><ul><li>Add a new JNDI name – a logical name (like a JCL //DD card) for your database. When creating this logical name, you will specify necessary database connection properties: </li></ul></ul></ul><ul><ul><ul><ul><li>Database Name, serverName (logical I/P name or address), port # </li></ul></ul></ul></ul><ul><ul><li>(One-time step) Add a new EGL Build file for your DB2 connection </li></ul></ul><ul><ul><ul><li>4. Add a new build file, and customize its sqlJNDIName to match your new JNDI Name </li></ul></ul></ul><ul><ul><li>(One-time step) Add an entry in your Project’s web.xml file </li></ul></ul><ul><ul><ul><li>5. Add a new sql resource reference in your Project’s web.xml file for the new JNDI Name </li></ul></ul></ul><ul><ul><li>Create a new web page </li></ul></ul><ul><ul><ul><li>6. Create a list page that uses the employeeDeptJoin record created in Lab3 </li></ul></ul></ul><ul><ul><li>Specify your new DB2 connection EGL Build File for the page’s JSFHandler </li></ul></ul><ul><ul><ul><li>7. Your JSFHandler needs to be generated with the correct DB2 access properties </li></ul></ul></ul><ul><li>Read the Notes of this slide before you begin! </li></ul>
    40. 40. *** REVIEW *** Specifying Connection Info to Databases <ul><li>For Web Applications (J2EE) </li></ul><ul><ul><li>JNDI Name in build descriptor </li></ul></ul><ul><ul><li>JNDI reference in web.xml </li></ul></ul><ul><ul><li>Project EAR File </li></ul></ul><ul><ul><ul><li>Application Deployment Descriptor </li></ul></ul></ul>Your EGL/JSF Web Page Steps 1, 2 3 Step 5 Step 4 Steps 6, 7 Note that you will have a new JNDI Name for your DB2 access in this lab – these screen captures show your current JNDI Name
    41. 41.  1. Add a new JAAS Authentication Entry <ul><li>From Project Explorer: </li></ul><ul><ul><li>Expand EGLWebEar </li></ul></ul><ul><ul><li>Open the Deployment tab </li></ul></ul><ul><ul><li>Scroll down and Add a new JAAS Authentication Entry – specifying your DB2 </li></ul></ul><ul><ul><ul><li>User ID </li></ul></ul></ul><ul><ul><ul><li>Password </li></ul></ul></ul>
    42. 42.  2 Create a new JDBC Provider <ul><li>Continuing on the Deployment tab… </li></ul><ul><ul><li>Scroll up and from Data Sources, add a new JDBC Provider </li></ul></ul><ul><ul><li>Under JDBC Provider List, click Add </li></ul></ul><ul><ul><li>Select: </li></ul></ul><ul><ul><ul><li>Database type: </li></ul></ul></ul><ul><ul><ul><ul><li>IBM DB2 </li></ul></ul></ul></ul><ul><ul><ul><li>JDBC provider type: </li></ul></ul></ul><ul><ul><ul><ul><li>DB2 Universal JDBC Driver Provider </li></ul></ul></ul></ul><ul><ul><li>From Create JDBC Provider </li></ul></ul><ul><ul><ul><li>Select and Remove the existing Class path external JARs </li></ul></ul></ul><ul><ul><ul><li>Click Add External JARs – and from your DB2 installation directory, browse to the java subdirectory and select the three JAR files shown below </li></ul></ul></ul><ul><ul><ul><li>Click Finish </li></ul></ul></ul>
    43. 43.  3. Create a new JNDI Name for your DB2 Database – 1 of 2 <ul><li>Continuing on the Deployment tab - Select your new JDBC… </li></ul><ul><ul><li>From Data source defined in the JDBC provider selected above, click: Add </li></ul></ul><ul><ul><li>From Create Data Source, select: </li></ul></ul><ul><ul><ul><ul><li>DB2 Universal JDBC Provider </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Click Next > </li></ul></ul></ul></ul><ul><ul><li>From Create Data Source </li></ul></ul><ul><ul><ul><li>Add these entries  </li></ul></ul></ul><ul><ul><ul><ul><li>Name </li></ul></ul></ul></ul><ul><ul><ul><ul><li>JNDI Name </li></ul></ul></ul></ul><ul><ul><ul><ul><li>( lower-case) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Use the combo-box </li></ul></ul></ul></ul><ul><ul><ul><ul><li>to select DB2Auth for </li></ul></ul></ul></ul><ul><ul><ul><ul><li>the Component and </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Container managed </li></ul></ul></ul></ul><ul><ul><ul><ul><li>authentication alias </li></ul></ul></ul></ul><ul><ul><ul><li>Click Next </li></ul></ul></ul>
    44. 44.  3. Create a new JNDI Name for your DB2 Database – 2 of 2 <ul><li>From Create Resource Properties, specify the following three property values: </li></ul><ul><ul><li>databaseName </li></ul></ul><ul><ul><ul><li> Enter: SAMPLE </li></ul></ul></ul><ul><ul><ul><li>- if you are using the Sample DB2 database on your PC </li></ul></ul></ul><ul><ul><ul><li>Enter your actual DB2 database name </li></ul></ul></ul><ul><ul><ul><ul><li>If you are accessing a remote DB2 database </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Example: REDBK1 </li></ul></ul></ul></ul><ul><ul><li>2. serverName </li></ul></ul><ul><ul><ul><li>Enter: localhost </li></ul></ul></ul><ul><ul><ul><ul><li>If you are using DB2 on your PC </li></ul></ul></ul></ul><ul><ul><ul><li>Enter the IP Address of your DB2 Server </li></ul></ul></ul><ul><ul><ul><ul><li>If you are accessing Remote DB2 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Ex. carmvs1.pok.ibm </li></ul></ul></ul></ul><ul><ul><li>3. portNumber </li></ul></ul><ul><ul><li>- which defaults to 50000 for localhost DB2 </li></ul></ul><ul><ul><li>- you will need the actual port# for your system – if you are accessing remote DB2 </li></ul></ul><ul><ul><li>Click Finish </li></ul></ul><ul><ul><li>Close your Application Deployment Descriptor </li></ul></ul><ul><ul><li>Save the changes to your EAR file </li></ul></ul>
    45. 45.  4. Add a New SQL Resource Reference to your Project’s web.xml file <ul><li>Add an entry in web.xml for the new JNDI name </li></ul><ul><ul><li>From Project Explorer, expand: WebContentsWEB-INF and open web.xml </li></ul></ul><ul><ul><li>From the References tab, click the Add … button </li></ul></ul><ul><ul><li>Add a  Resource reference </li></ul></ul><ul><ul><ul><li>Click Next > </li></ul></ul></ul><ul><ul><li>Enter the settings shown here  </li></ul></ul><ul><ul><li>Name: jdbc/sample </li></ul></ul><ul><ul><li>Type: Open the combo-box. Scroll to the bottom and select </li></ul></ul><ul><ul><li>javax.sql.DataSource </li></ul></ul><ul><ul><li>Authentication: Open the combo-box and select: Container </li></ul></ul><ul><ul><li>And add the jdbc/sample JNDI name to the WebSphere Bindings  </li></ul></ul><ul><ul><li>Close and save web.xml </li></ul></ul>
    46. 46.  5. Create a new EGL Build File for your DB2 Connection <ul><li>As you did in a previous lab in this course, you will create a new Build File, and then modify it’s entry so that it references your DB2 JNDI name. From Project Explorer… </li></ul><ul><ul><li>Right-Click over EGLSource and select: </li></ul></ul><ul><ul><ul><li>New, Other, expand EGL, and select EGL Build File </li></ul></ul></ul><ul><ul><li>Name the file DB2Build and close your new build file </li></ul></ul><ul><li> Copy the contents of EGLWeb Build File entries into DB2Build </li></ul><ul><ul><li>Right-Click over EGLWeb.eglbld and select: Open with Text Editor </li></ul></ul><ul><ul><li>Click anywhere inside the file, and press </li></ul></ul><ul><ul><ul><li>Ctrl/A - to select all text </li></ul></ul></ul><ul><ul><ul><li>Ctrl/C - to copy the selected text </li></ul></ul></ul><ul><ul><li>Close EGLWeb.eglbld </li></ul></ul><ul><ul><li>Right-Click over DB2Build.eglbld and select: Open with Text Editor </li></ul></ul><ul><ul><li>Click anywhere inside the file, and press Ctrl/V - to paste the copied text </li></ul></ul><ul><li>1. Change the sqlJNDIName= value </li></ul><ul><li>2. Be sure that J2EE=“YES” </li></ul><ul><li>Close DB2Build.eglbld and Save </li></ul>&quot; jdbc/sample &quot; J2EE= &quot; YES &quot;
    47. 47.  6. Create a new Page – 1 of 3 <ul><li>From Project Explorer, Right-click over WebContents and create a new Web Page, named: testDB2Page.jsp </li></ul><ul><ul><li>Create it using a template from the MyTemplates folder </li></ul></ul><ul><li>Modify the default page title text </li></ul><ul><li>Right-click over the page in the content area </li></ul><ul><li>Select Edit Page Code </li></ul><ul><li>Select all of the existing JSFHandler boiler-plate statements and replace them with the code in the Notes section of this slide </li></ul><ul><li>Save ( Ctrl/S ) your code </li></ul><ul><li>There shouldn’t be anything </li></ul><ul><li>new in this code that you </li></ul><ul><li>haven’t seen before in other </li></ul><ul><li>sections of this course. </li></ul><ul><li>… we hope  </li></ul>
    48. 48.  6. Create a new Page – 2 of 3 <ul><li>From Page Designer, from the Page Data area </li></ul><ul><li>Select empArray – drag and drop it onto the page </li></ul><ul><li>From Configure Data controls, select:  Displaying an existing record (read/only) </li></ul><ul><li>Select just the seven fields shown below </li></ul><ul><li>With the control selected, access the Properties tab </li></ul><ul><ul><li>Specify Border 1 </li></ul></ul>
    49. 49.  (Optional) 6. Create a new Page – 3 of 3 <ul><li>From Page Designer, with the entire dataTable selected (see Notes***) – from Properties </li></ul><ul><li>Select the – Display options sub-tab </li></ul><ul><li>Delete the existing Column classes: value </li></ul><ul><li>Click Add column to categorize table rows </li></ul><ul><li>This will add a new column to the left side of the dataTable for data grouping </li></ul><ul><li>With your new column selected </li></ul><ul><li>From the new columns Value: Click the browse button </li></ul><ul><li>Expand empArray and select DEPTNAME </li></ul><ul><li>This specifies that the dataTable rows should be aggregated (grouped by) DEPTNAME </li></ul>
    50. 50.  7. Specify the New Build File for Your Web Page <ul><li> Before running your page, you must assign the JSFHandler to your new Build File – in order for the EGL generation to pick up the proper JNDI Name to access the DB2 Sample database. </li></ul><ul><li>From Project Explorer: </li></ul><ul><li>Expand EGLSourcejsfhandlers </li></ul><ul><li>Right-click over testDB2Page.egl and select: Properties </li></ul><ul><li>From Properties, select EGL Default Build Descriptor </li></ul><ul><li>For both the Target system and Debug build descriptors, open the combo-box and select: </li></ul><ul><li>EGLWebWebBuildOptions <EGLWeb/EGLsource/DB2Build.eglbld> </li></ul><ul><li>Click OK </li></ul>
    51. 51.  Run the Page <ul><li>Right-click over the content area, and select: Run on server </li></ul><ul><li>Click the triangle (twisties) to expand/collapse Departments </li></ul>Click to expand 

    ×