Database access using the iSeries
To run this example using a database on the iSeries, you must create the database on the iSeries and create a new data source for the database in the server configuration.
Contents
Creating a new server configuration
Creating the database on the iSeries
Creating a new data source for the database
Configuring the data source on the iSeries
- From the Server Configuration view, right-click New > Server and Server Configuration.
- In the Create a New Server and Server Connection window, enter the following values:
- Server name: Server using DataSource on iSeries
- Folder: AutoworldSRV
- Server type: WebSphere version 5.0/Test Environment
- Template: None
- Click Finish.
In the Server Configuration view, ensure that the EAR file you specified for this project is
associated with the new server configuration by right-clicking on the
server configuration and selecting Add > EAR_filename.
To run the example, the driver file that accesses the
iSeries database must be locally available on your workstation. The driver file
name is jt400.jar and is located in the IFS of the iSeries in
/QIBM/ProdData/HTTP/Public/lib/jt400.jar. You can copy the jt400.jar file to a hard drive on your
workstation.
Before you create the database on the iSeries, create the user ID SAMPLE on the iSeries. Then create a library on the iSeries by typing the following from an OS/400 command line and pressing Enter:
CRTLIB SAMPLE
To create the tables on the iSeries:
- Right-click Table.dll.
- Select Run on Database Server... from the popup menu.
- Click Next in the Run Script window.
- Select Commit changes only upon success and click Next
on the Options window.
- Enter the following values in the Database Connection window
and click Finish:
- Database: SAMPLE
- user ID: sample
- Password: Your iSeries password
- Database vendor type: DB2 Universal Database for iSeries,
V5R1
- JDBC driver: AS/400 Toolbox for Java JDBC Driver
- Host: system_name
- Class location: Specify the location of the jt400.jar
file referenced earlier
- Accept the defaults for all other fields.
- Verify that there are no errors in the Confirm export results
window and click Commit changes.
Create a schema for the SAMPLE
database on the iSeries. Type the
following from an OS/400 command line and press Enter:
CREATE SCHEMA SAMPLE
You
must now configure the server so the example will access the database on the iSeries instead of the pre-configured Cloudscape database.
Now create a data source that will reference the iSeries database. Double-click the server configuration you created for WebSphere version 5.0/Test Environment and click the Data Source tab.
Define the JDBC Provider:
-
Click Add... in the JDBC provider list section to add a new JDBC provider.
- Select IBM DB2 in the Database type: list.
- Select DB2 UDB for iSeries (Toolbox) in the JDBC Provider type: list and click Next.
- Enter the following values and click Finish on the Create a JDBC Provider dialog:
- Name: iSeries Toolbox
- Implementation class name: com.ibm.as400.access.AS400JDBCConnectionPoolDataSource
- Class path: drive:\path_name\jt400.jar (by clicking Add External JARs...)
Define the Data Source:
- Ensure iSeries Toolbox is selected in the JDBC provider
list: section and click Add... in the Data source defined
in the JDBC provider selected above: section.
- Select Version 4.0 data source and click Next.
- Enter the following values and click Finish on the Modify Data Source page:
- Name: Sample Database
- JNDI name: Sample
- Database name: sample
- Default user ID: sample
- Default user password: ******
- Click
Add... in the Resource properties defined in the data source selected above: list and enter the following values:
- Name: serverName
- Type: java.lang.String
- Value: system_name (the name of the iSeries server specified when you created the database)
- Click Ok.
Now save the server configuration and restart the server for the
changes to take effect. When you run the example, the tables on the
iSeries will be used.
If you want to deploy and run this web application on the iSeries, you must create a data source for the sample files. To create the data source, go to the WebSphere administration page by opening a web browser and going to http://system_name:9090/admin. Perform the following steps from the administration page:
- Expand Security in the left frame, then expand JAAS
Configuration.
- Click J2C Authentication Data.
- Click New on the J2C Authentication Data Entries page.
- On the New page, specify an alias for this entry as well as your iSeries user ID and password and click Apply.
Now create a data source that will reference the iSeries database.
Define the JDBC Provider:
- Expand Resources in the left frame and click JDBC
Providers.
- Click New on the JDBC Providers page to create a new
provider.
- Select DB2 UDB for iSeries (Toolbox) from the provider list
and click Apply.
Define the Data Source:
- Return to the JDBC Provider page and click the DB2 UDB
for iSeries (Toolbox) entry.
- Click Data Sources at the bottom of the Configuration page.
- Click New on the Data Sources page to create a new
data source.
- Enter the following values on the New page:
- Name: sample
- JNDI Name: Sample
- Component-managed Authentication Alias: Type the name of
the system specified for the serverName field earlier in this example.
- Container-managed Authentication Alias: Type the name of
the system specified for the serverName field earlier in this example.
- Click Apply to create the data source.
- Click the data source you just created on the Data Sources page.
- Click Custom Properties at the bottom of the page.
- Click Next to go to page 2.
- Click serverName at the bottom of the page and specify the
name of the server that has the example tables.
- Click Apply.
- Click Save at the top of the administration page to save the
workspace changes.
Export the EAR file to the iSeries and install the application.
Limitations
Disclaimer:
The following [enclosed] code is sample code created by IBM
Corporation. This sample code is not part of any standard IBM product
and is provided to you solely for the purpose of assisting you in the
development of your applications. The code is provided 'AS IS',
without warranty or condition of any kind. IBM shall not be liable
for any damages
arising out of your use of the sample code, even if IBM has been
advised of the possibility of such damages.