®
IBM Software Group
© 2006 IBM Corporation
Creating a New Project and Connecting it to the DB2 Sample Database and WAS 6.1
2
Create New Dynamic Web Project
From the File menu, select: New > Project… From the new project wizard, select
Dynamic Web Project
Specify (carefully) Project Name: Target Runtime
Configurations
Add project to EAR file
Note that several of these options will be pre-selected
Click Click NNext >ext >
3
Specify Project Facets
From Project Facets, check the following options for your new project:
Default style sheet
Both of the EGL options
Both of the WebSphere Web options
No other options!
Click Next >Click Next >
4
Add EGL Settings
Click Next > Click Next > past the next setup menu (Accept defaults for folder names)
From EGL SettingEGL Setting, carefully enter the JNDI name to connect to your database:
jdbc/sample
Click Click FinishFinish
Click Yes to Open the Associated Web Perspective
Close the Web Diagram tool, open by default in the Content Area
5
Create a Connection From your EAR File to DB2
This is a multi-step 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 #
Create a new web page4. Create a list page that uses the employeeDeptJoin record
Read the Notes of this slide before you begin!
6
*** Note*** Note that you will have a new 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 the JNDI Name from our show the JNDI Name from our
Training database Training database
*** Note*** Note that you will have a new 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 the JNDI Name from our show the JNDI Name from our
Training database Training database
*** 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
7
1. Add a new JAAS Authentication Entry
From Project Explorer: Expand <ProjectName>EAR Open the Deployment tab Scroll down and Add a new JAAS Authentication Entry – specifying your DB2
User ID Password
8
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
9
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
10
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
11
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
12
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
13
Use the Connection to SQLRetrieve Schema into an EGL Record1. Scroll to the bottom of the Pagehandler, 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
14
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
15
(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