1 Last update: Unit Connecting to External Data Sources – Connecting to External Data Sources – on the i5 on the i5 Topics: Appendices Appendices
1Last update: 12/04/2007
Unit
Connecting to External Data Sources – on the i5Connecting to External Data Sources – on the i5
Topics:
AppendicesAppendices
2Last update: 12/04/2007
Topics – Access to Mainframe – System i and System z – Data
What’s Possible? SQL Access
How to do it? Configuration Possibilities Specifying Connection Information Specifying Jar File Locations Miscellaneous
Access to Files Remote From Generated COBOL programs
Lab accessing DB2
Note: Original materials by Mark Evans: - [email protected]
EGL Logic PartEGL Logic Part
Data AccessData Access
EGL Logic PartEGL Logic Part
Data AccessData Access
System z or IBM iSystem z or IBM i
3Last update: 12/04/2007
Options - Non-Relational Data Access from EGL (COBOLGEN only)
System z - from Generated COBOLSystem z - from Generated COBOL Serial files – (QSAM files on the host) Indexed, relative keys (VSAM files on the host) CICS
Transient Data Queues Temporary Storage Queues Spool
System i - from Generated COBOLSystem i - from Generated COBOL File Access
Serial Indexed Relative Record
Note: Data Queues are accessible only through called CL programs, not direct.
4Last update: 12/04/2007
Other Remote Data Access from EGL Debugger and Java Gen Parts QSAMQSAM – sequential files
AIX, Windows only As standard external files, defined as resource associations
VSAMVSAM - Indexed, relative key files Uses EGL supplied Distributed File Manager support
– VSAMWIN.zip in plug-in directories
SNA (or TCP62) based
– Requires SNA client product (like IBM Personal Communications) to supply protocol drivers
Reference doc: WDz6RemoteVSAM.pdf
5Last update: 12/04/2007
Relational – SQL Data Access from EGL (Java Gen)
Control/Specify access to: DB2,Oracle, Derby, MS-SQLServer, etc) Requires JDBC driver and access to jar/zip file containing the class
– Example: com.ibm.db2.jcc.DB2Driver
Connect to database via Connection URL– Example: jdbc:db2://localhost:50000/SAMPLE
Or, connect to database via JNDI name– Example: jdbc/sample
EGL does not know or care that it is connecting to a remote database (System i or System z) It just connects to a– URL (non-J2EE)
– JNDI name (J2EE)
6Last update: 12/04/2007
Remote Access from EGL – DB2 on z/OS What’s required to make this work?
IBM Universal JDBC Driver + Valid DB2 Connect License Jar ***Notes DB2 V8.1 or later Just supply access information Reference Doc: DB2Unicon.doc
DB2 Host Name DB2 Host Port DB2 Location
Jar file for Universal Driver License Jar file for Remote z/OS connection
7Last update: 12/04/2007
Remote Access from EGL – DB2/400 on i5 Access done through System i Java Toolkit supplied JDBC Driver What’s required to make this work?
JT400.jar Valid connection information, authentication and permissions
IP Address of the host machine User ID Password System or sql schema
Host Name of System i machineURL must specify as400JT400 jar file containing AS400JDBCDriver class
8Last update: 12/04/2007
Getting the JT400 Toolkit for DB2 access – System i
or With WDSC, in the following directory
In your installation directory
…or... From the System i directories
\QIBM\ProdData\HTTP\Public\j4400\lib
9Last update: 12/04/2007
Workshop – Connect Your EGLWeb Project to Your i5 DB2/400 Data (Tomcat)
Assuming you have all the proper authorizations, you will do the following: Create a new connection – to your i5 and DB2400 Make this new connection the default connection Customize the Tomcat context.xml – to point to your i5 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)
Run the Data Access Wizard to generate new SQLRecords and Libraries for your i5 DB2 tables
Create a page that uses the SQLRecords and accesses i5 data
10Last update: 12/04/2007
Specifying Connection Info to Databases – 1 of 4
Use EGL SQL Database Connection Preference …for
SQL Retrieve SQL Statement Validation EGL Debugger if not in debug build descriptor
From Preferences, select: SQL Database Connections SQL Database Connections Click: New…
11Last update: 12/04/2007
Specifying connection info to Databases – 2 of 4
Select: DB2 for i5/OSDB2 for i5/OS
Enter the following: Hostname, or
“ping-able” IP address User IDUser ID PasswordPassword
Click: TTest Connectionest Connection
Click Next >Next >
12Last update: 12/04/2007
Specifying connection info to Databases – 3 of 4
Specify: Disable filterDisable filter SelectionSelection
Check: However many
libraries you’d like to do development in
Click: FFinishinish
13Last update: 12/04/2007
Specifying connection info to Databases – 4 of 4
Ensure that your new, i5 connection is the default – Click Apply then OK
14Last update: 12/04/2007
Specifying Database Connection – WebSphere
For Web Applications (J2EE) sqlJNDI Name in build descriptor
JNDI reference in web.xml
Project EAR File Application Deployment Descriptor
DB2DB2
15Last update: 12/04/2007
Specifying Database Connection – Tomcat
For Web Applications (J2EE) sqlJNDI Name in build descriptor
context.xml (Resource driverClassname) context.xml (Resource driverClassname) in \WebContent\META-INF
DB2DB2
16Last update: 12/04/2007
Connecting a Tomcat Application Server to an AS/400 Database
You will need to do the following, to connect your Tomcat Server to an AS/400 Database:1. Add the necessary jdbc client/driver .JAR files to you’re the tomcat: \common\lib\\common\lib\ folder 2. Customize a <Resource … entry in your project’s context.xmlcontext.xml
Here is an example of such a <Resource entry for an AS/400 JDBC driver:
<Resource driverClassName="com.ibm.as400.access.AS400JDBCDriver"<Resource driverClassName="com.ibm.as400.access.AS400JDBCDriver"
maxActive="4" maxIdle="2" maxWait="5000" auth="Container"maxActive="4" maxIdle="2" maxWait="5000" auth="Container"
name="jdbc/<yourlogicalJNDIname>" password="xxxxxxx"name="jdbc/<yourlogicalJNDIname>" password="xxxxxxx"
type="javax.sql.DataSource"type="javax.sql.DataSource"
url="jdbc:<your connection URL>;naming=system;"url="jdbc:<your connection URL>;naming=system;"
username=“<your user ID>"/>username=“<your user ID>"/>
17Last update: 12/04/2007
Modify Your Project’s context.xml File (add a new Resource for accessing your i5)
From Project Explorer: Open \WebContent\META-INF\\WebContent\META-INF\context.xmlcontext.xml From the Slide *** Notes – copy/paste the sample <Resource driverClassName into the
file as shown in the screen capture below. Then modify the: name and password: name=“jdbc/i5” password=“your password” url (carefully specify your HostName) Username: (your user id)
Save your changesSave your changes
18Last update: 12/04/2007
Customize the Project’s BuildFile
From Project Explorer: Open \EGLSource\EGLWeb.eglbld\EGLSource\EGLWeb.eglbld Click into the sqlJNDIName value (Left-click to edit)
Change the sqlJNDIName to match your new i5 Resource driverClassName: jdbc/i5jdbc/i5 Save your changesSave your changes
19Last update: 12/04/2007
Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables
From Project Explorer: Right-click over \EGLSource\ Select: New > Other >
From Select a wizard: Expand the EGL category Select: EGL Data Access Application Click: Next >
From Define project settings: Open the Project Name combo-box, and
select: EGLWebEGLWeb Open the Database Connection combo-box,
and select your new i5 named connection Select your tables (not too many?) Click Next >
20Last update: 12/04/2007
Use the Data Access Wizard to Create SQLRecords and Functions for Accessing your i5 DB2 Tables
From Define the Fields Choose a key field for each table Click: Next >
From Define project creation options Check: Qualify table names with schema
Click Finish
21Last update: 12/04/2007
Create a Page to Access your i5 Data
From Project Explorer: Right-click over: \WebContent\\WebContent\ Specify: New > Web PageNew > Web Page Name the page: yourPage.yourPage.jspjsp
Modify the boiler-plate heading text, and edit the EGL
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
22Last update: 12/04/2007
Create a Page to Access your i5 Data
With your cursor between the get <variableName> statement, Right-click Select:
SQL Statement Add
23Last update: 12/04/2007
Create a Page to Access your i5 Data
Add a Where clause – similar to the one shown here Example:Example:where <field> > :searchfieldwhere <field> > :searchfield
Optionally modify the order by order by clause
Save your EGL codeSave your EGL code
From Project Explorer, From Project Explorer,
Note: colon prefix
:searchField:searchField
Generate your projectGenerate your project
24Last update: 12/04/2007
Create a Page to Access your i5 Data From Page Designer – from Page Data:
Drag searchFieldsearchField onto the page, and create an input field with a single Submit Button Drag searchFuncsearchFunc on top of the Submit Button 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 Optionally, drag an HTML Rule between the Submit Button and dataTable
25Last update: 12/04/2007
Create a Page to Access your i5 Data (optional styling) From Page Designer – Properties, with the dataTable selected
From the hx:dataTable property: Give the dataTable a Border From Display options, specify:
No Column class (for alternate row colors) A scrollable area
26Last update: 12/04/2007
Run the Page – and Search Right-Click over your page, and select: Run on server Enter a valid search criteria and click the Search button
27Last update: 12/04/2007
Database Connections – Allowing the Data Source to Define the SchemaPProblem: 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?
AAnswer: 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 with2. 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**Notes
28Last update: 12/04/2007
Database Connections – Adding Custom Properties to JDBC Drivers
PProblem: 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.
AAnswer: 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: AddAdd2. To allow access to uncommitted rows, provide the Name/Type and Value shown in the screen capture3. To learn more about customizing a DataSource, read the following IBM Document:
http://www-1.ibm.com/support/docview.wss?rs=180&uid=swg21224492
29Last update: 12/04/2007
Database Connections JT400 – Setting Binary Translation on For CCSID Problems
PProblem: Why are my web pages returning hexadecimal characters to my .JSP page or EGL program?
AAnswer: 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):
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, 1. Scroll down to find the translateBinarytranslateBinary property entry2. Click: EditEdit3. Value: true4.4. SaveSave your changes to the Deployment Descriptor5.5. Restart your serverRestart your server
***Notes***Notes
30Last update: 12/04/2007
Specifying Connection Info to Databases – 4 of 4 For non-J2EE Generated Java Apps
and Debug (if not using EGL Preferences)
In Build descriptor sqlDB
– Connection URL
sqlJDBCDriverClass– Class to use for connection
Which results in rununit.properties entries
Found in JavaSource folder
31Last update: 12/04/2007
Adding Jar file to Classpath for JDBC Drivers – 1 of 3 For J2EE Apps:
WAS JDBC Provider definition
plus
WAS WebSphere Variables
32Last update: 12/04/2007
Adding Jar file to Classpath for JDBC Drivers – 2 of 3
For non-J2EE Generated Java Apps
and
Debug (if not using EGL Preferences)
In Java Build Path of Project Properties
33Last update: 12/04/2007
Adding Jar file to Classpath for JDBC Drivers – 3 of 3 Debug (if using EGL
Preferences) Mainly used for customers
who are only generating COBOL for deployed apps
34Last update: 12/04/2007
Miscellaneous - SQLRetrieve Preferences for COBOL Gen
record employee type SQLRecord
{tableNames = [["DRBRUCE.EMPLOYEE"]]}
10 EMPNO char(6) {column="EMPNO", isNullable=yes};
10 FIRSTNME char(12) {column="FIRSTNME", isNullable=yes;
10 MIDINIT char(1) {column="MIDINIT", isNullable=yes};
10 LASTNAME char(15) {column="LASTNAME", isNullable=yes;
10 HIREDATE char(10) {column=“HIREDATE", isNullable=yes};
10 ..
record employee type SQLRecord
{tableNames = [["DRBRUCE.EMPLOYEE"]]}
EMPNO string {column="EMPNO", isNullable=yes, maxLen=6};
FIRSTNME string {column="FIRSTNME", isNullable=yes,
maxLen=12};
MIDINIT string {column="MIDINIT", isNullable=yes, maxLen=1};
LASTNAME string {column="LASTNAME", isNullable=yes,
maxLen=15};
HIREDATE date {column=“HIREDATE", isNullable=yes};
Instead of…
Prod
uces
35Last update: 12/04/2007
Available Materials (Access to Remote Resources)
Documents on DeveloperWorks: DB2Unicon.doc - database setup for DB2 on z/OS access iSeriesTutorial.doc - includes database setup for DB2 on iSeries access db2oniSeriesSetup.doc - database setup for DB2 on iSeries WDz6RemoteVSAM.pdf - Remote VSAM access to z/OS from EGL
debugger
36Last update: 12/04/2007
Lab1 – Configure a Connection for DB2
From Window >
Preferences > EGL > SQL Database Connection
Create a new connection, and specify parameters for DB2
Note that, if you have DB2 installed locally on your machine, you may use DB2 UDB (You will have to select the proper version)
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.
Press Test Connection to test your settings.
Click Finish
37Last update: 12/04/2007
Lab2 – Use the Connection in the Data Perspective
From Window Open
Perspective Other Data… Using your
skills from the previous unit in this course, explore a DB2 database using your new Connection
Here we are showing the SAMPLE DB2 database
38Last update: 12/04/2007
Lab3 – Use the Connection to SQLRetrieve Schema into an EGL Record
1. From the Web Perspective, open CustomerLib.egl. Scroll to the bottom, and enter the following record statement: 2. With your cursor inside the statement, Right-Click and select: SQL Record > Retrieve SQL
3. Press Ctrl/S (Save)
SAMPLESAMPLE
DatabaseDatabase
Catalog
Read slide Notes*** Read slide Notes*** Read slide Notes*** Read slide Notes***
You will You will need to need to enter enter YOURYOUR schema schema name – not name – not jsaylesjsayles
You will You will need to need to enter enter YOURYOUR schema schema name – not name – not jsaylesjsayles
39Last update: 12/04/2007
Lab4 – Create a Connection From your EAR File to DB2
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:
(One-time step) Customize your project’s EAR file entries:1. Add a new JAAS Authentication Alias – so your pages can login and access DB2 data
2. Add a new JDBC Provider to DB2 – specify a logical name that points to your DB2 client/connectivity software
3. 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:
Database Name, serverName (logical I/P name or address), port #
(One-time step) Add a new EGL Build file for your DB2 connection4. Add a new build file, and customize its sqlJNDIName to match your new JNDI Name
(One-time step) Add an entry in your Project’s web.xml file5. Add a new sql resource reference in your Project’s web.xml file for the new JNDI Name
Create a new web page6. Create a list page that uses the employeeDeptJoin record created in Lab3
Specify your new DB2 connection EGL Build File for the page’s JSFHandler7. Your JSFHandler needs to be generated with the correct DB2 access properties
Read the Notes of this slide before you begin!
40Last update: 12/04/2007
*** REVIEW *** Specifying Connection Info to Databases
For Web Applications (J2EE) JNDI Name in build descriptor
JNDI reference in web.xml
Project EAR File Application Deployment Descriptor
YourYour
EGL/JSFEGL/JSF
WebWeb
PagePage
Steps 1, 2 3Steps 1, 2 3
Step 5Step 5
Step 4Step 4
Steps 6, 7Steps 6, 7
Note that you will have a new Note that you will have a new
JNDI Name for your DB2 accessJNDI Name for your DB2 access
in this lab – these screen capturesin this lab – these screen captures
show your current JNDI Nameshow your current JNDI Name
Note that you will have a new Note that you will have a new
JNDI Name for your DB2 accessJNDI Name for your DB2 access
in this lab – these screen capturesin this lab – these screen captures
show your current JNDI Nameshow your current JNDI Name
41Last update: 12/04/2007
1. Add a new JAAS Authentication Entry
From Project Explorer: Expand EGLWebEar Open the Deployment tab Scroll down and Add a new JAAS Authentication Entry – specifying your DB2
User ID Password
42Last update: 12/04/2007
2 Create a new JDBC Provider
Continuing on the Deployment tab… Scroll up and from Data Sources, add a new JDBC Provider Under JDBC Provider List, click Add
Select: Database type:
– IBM DB2
JDBC provider type:– DB2 Universal JDBC Driver Provider
From Create JDBC Provider Select and Remove the existing Class path external JARs Click Add External JARs – and from your DB2 installation directory, browse to the \java\ subdirectory
and select the three JAR files shown below
Click Finish
43Last update: 12/04/2007
3. Create a new JNDI Name for your DB2 Database – 1 of 2
Continuing on the Deployment tab - Select your new JDBC… From Data source defined in the JDBC provider selected above, click: AddAdd From Create Data Source, select:
– DB2 Universal JDBC Provider– Click Next >Next >
From Create Data Source Add these entries
– Name– JNDI Name
(lower-case)
– Use the combo-boxto select DB2Auth forthe Component and Container managedauthentication alias
Click Next
44Last update: 12/04/2007
3. Create a new JNDI Name for your DB2 Database – 2 of 2
From Create Resource Properties, specify the following three property values:
1.1. databaseNamedatabaseName
Enter: SAMPLESAMPLE- if - if you are using the Sample DB2 database on your PC
Enter your actual DB2 database name– If you are accessing a remote DB2 database– Example: REDBK1
2.2. serverNameserverName
Enter: localhostlocalhost If you are using DB2 on your PC
Enter the IP Address of your DB2 Server If you are accessing Remote DB2– Ex. carmvs1.pok.ibm
3.3. portNumberportNumber- which defaults to 5000050000 for localhost DB2- you will need the actual port# for your system – if you are accessing remote DB2
Click Finish
Close your Application Deployment Descriptor Save the changes to your EAR file
45Last update: 12/04/2007
4. Add a New SQL Resource Reference to your Project’s web.xml file
Add an entry in web.xml for the new JNDI name From Project Explorer, expand: \WebContents\WEB-INF\ and open web.xmlweb.xml
From the ReferencesReferences tab, click the Add… button
Add a Resource reference Click Next >
Enter the settings shown here
Name: jdbc/sampleType: Open the combo-box. Scroll to the bottom and select javax.sql.DataSourceAuthentication: Open the combo-box and select: Container
And add the jdbc/samplejdbc/sample JNDI name to the WebSphere Bindings
Close and save web.xml
46Last update: 12/04/2007
5. Create a new EGL Build File for your DB2 Connection
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… Right-Click over \EGLSource\\EGLSource\ and select:
New, Other, expand EGL, and select EGL Build File Name the file DB2Build DB2Build and close your new build file
Copy the contents of EGLWeb Build File entries into DB2Build Right-Click over EGLWeb.eglbld EGLWeb.eglbld and select: Open with Text Editor Click anywhere inside the file, and press
Ctrl/A - to select all text Ctrl/C - to copy the selected text
Close EGLWeb.eglbld Right-Click over DB2Build.eglbld DB2Build.eglbld and select: Open with Text Editor Click anywhere inside the file, and press Ctrl/VCtrl/V - to paste the copied text
1. Change the sqlJNDIName=sqlJNDIName= value
2. Be sure that J2EE=“YES”
Close DB2Build.eglbld and Save"jdbc/sample"
J2EE="YES"
47Last update: 12/04/2007
6. Create a new Page – 1 of 3
From Project Explorer, Right-click over \WebContents\ and create a new Web Page, named: testDB2Page.jsptestDB2Page.jsp Create it using a template from the MyTemplates folder
Modify the default page title text Right-click over the page in the content area Select Edit Page Code Select all of the existing
JSFHandler boiler-plate statements and replace them with the code in the Notes section of this slide
Save (Ctrl/SCtrl/S) your code
There shouldn’t be anything new in this code that you haven’t seen before in other sections of this course. …we hope
48Last update: 12/04/2007
6. Create a new Page – 2 of 3
From Page Designer, from the Page Data area Select empArray – drag and drop it onto the page From Configure Data controls, select: Displaying an existing record (read/only) Select just the seven fields shown below With the control selected, access the PropertiesProperties tab
Specify Border 1
49Last update: 12/04/2007
(Optional) 6. Create a new Page – 3 of 3
From Page Designer, with the entire dataTable selected (see Notes***) – from Properties Select the – Display options sub-tab Delete the existing Column classes: value
Click Add column to categorize table rowsThis will add a new column to the left side of the dataTable for data grouping
With your new column selected From the new columns Value: Click the browse button
Expand empArray and select DEPTNAMEThis specifies that the dataTable rows should be aggregated (grouped by) DEPTNAME
50Last update: 12/04/2007
7. Specify the New Build File for Your Web Page
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.
From Project Explorer: Expand \EGLSource\jsfhandlers\ Right-click over testDB2Page.egl and select: Properties From Properties, select EGL Default Build Descriptor For both the Target system and Debug build descriptors, open the combo-box and select:
EGLWebWebBuildOptions <EGLWeb/EGLsource/DB2Build.eglbld>EGLWebWebBuildOptions <EGLWeb/EGLsource/DB2Build.eglbld>
Click OKOK
51Last update: 12/04/2007
Run the Page
Right-click over the content area, and select: Run on server Click the triangle (twisties) to expand/collapse Departments
Click to expand