This tutorial begins where Tutorial: Reusing Existing COBOL Programs in a Java Web Services Environment left off, using the Apache Tomcat application server, and the same CobolBook and JSPBookDemo projects. Therefore, you must complete that tutorial in its entirety, using the Tomcat 7 application server, before starting this tutorial. See Tutorial: Reusing Existing COBOL Programs in a Java Web Services Environment for complete instructions.
You must also install IBM DB2 LUW version 10 Express-C 32-bit.
This section explains the modifications you need to make to the SQL Server version of the tutorial so that the application works with DB2 LUW instead of SQL Server.
This replaces the db2jcc.jar file on the list, and prompts you to update the other .jar file paths to use the same location. Because you are just adding a single .jar file in an alternative directory, updating the path for other files is not required.
This adds the file to the Driver file list.
Property | Value |
---|---|
Connection URL | jdbc:db2://localhost:50000/SAMPLE |
Database Name | SAMPLE |
Driver Class | com.ibm.db2.jcc.DB2Driver |
Password | blank |
User ID | blank |
DROP TABLE BOOKS; CREATE TABLE BOOKS ( TITLE VARCHAR(50) NOT NULL, TYPE VARCHAR(20) NOT NULL, AUTHOR VARCHAR(50) NOT NULL, STOCKNO CHAR(4) NOT NULL PRIMARY KEY, ISBN DECIMAL (13, 0) NOT NULL, RETAIL DECIMAL(4,2) NOT NULL, ONHAND INT NOT NULL, SOLD INT NOT NULL ); INSERT INTO BOOKS VALUES( 'OLIVER TWIST', 'CHARLES DICKENS', 'CLASSIC', '1111', 9780140620467, 5.00, 10, 30 ); INSERT INTO BOOKS VALUES( 'A GAME OF THRONES', 'GEORGE R. R. MARTIN', 'FANTASY', '1112', 7428545, 3.86, 17, 75 ); INSERT INTO BOOKS VALUES( 'A CLASH OF KINGS', 'GEORGE R. R. MARTIN', 'FANTASY', '1113', 7447833, 6.49, 17, 75 ); INSERT INTO BOOKS VALUES( 'THE DAY OF THE JACKAL', 'FREDERICK FORSYTH', 'ADVENTURE', '1114', 99552710, 2.00, 26, 75 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE PHILOSOPHER''S STONE', 'J. K. ROWLING', 'ADVENTURE', '1116', 747558191, 5.24, 48, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE CHAMBER OF SECRETS', 'J. K. ROWLING', 'ADVENTURE', '1117', 747562180, 5.24, 44, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE PRISONER OF AZKABAN', 'J. K. ROWLING', 'ADVENTURE', '1118', 747573760, 5.24, 49, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE GOBLET OF FIRE', 'J. K. ROWLING', 'ADVENTURE', '1119', 747582386, 6.74, 44, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE ORDER OF THE PHOENIX', 'J. K. ROWLING', 'ADVENTURE', '1120', 747591261, 6.74, 37, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE HALF-BLOOD PRINCE', 'J. K. ROWLING', 'ADVENTURE', '1121', 747598460, 6.74, 41, 100 ); INSERT INTO BOOKS VALUES( 'HARRY POTTER AND THE DEATHLY HALLOWS', 'J. K. ROWLING', 'ADVENTURE', '1122', 1408810298, 6.74, 40, 100 ); INSERT INTO BOOKS VALUES( 'THE FELLOWSHIP OF THE RING', 'J. R. R. TOLKIEN', 'FANTASY', '1123', 7123825, 4.95, 23, 100 ); INSERT INTO BOOKS VALUES( 'THE TWO TOWERS', 'J. R. R. TOLKIEN', 'FANTASY', '1124', 261102362, 7.99, 28, 100 ); INSERT INTO BOOKS VALUES( 'LORD OF THE FLIES', 'WILLIAM GOLDING', 'SCARY', '2222', 9780571191475, 4.50, 30, 100 ); INSERT INTO BOOKS VALUES( 'CATCH 22', 'JOSEPH HELLER', 'WAR', '3333', 9780099477310, 6.50, 50, 200 ); INSERT INTO BOOKS VALUES( 'THE HITCHHIKER''S GUIDE TO THE GALAXY', 'DOUGLAS ADAMS', 'COMEDY', '4444', 9780345453747, 6.73, 100, 360 ); INSERT INTO BOOKS VALUES( 'TO KILL A MOCKINGBIRD', 'HARPER LEE', 'CLASSIC', '5555', 9780099466734, 4.87, 50, 75 ); SELECT * FROM yourSchema.BOOKS; SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY
exec sql connect to PUBS end-exec
To:
exec sql connect to db2 end-exec
<Resource name="db2" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="10" maxWait="10000" username="db2UserName" password="db2Password" driverClassName="com.ibm.db2.jcc.DB2Driver" url="jdbc:db2://localhost:50000/sample:retrieveMessagesFromServerOnGetMessage=true;"/>
Replacing db2UserName and db2Password with your DB2 database credentials, or if applicable, your Windows authentication credentials.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>JSPBookDemo</display-name> <servlet> <servlet-name>BookServlet</servlet-name> <servlet-class>com.microfocus.book.BookServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>BookServlet</servlet-name> <url-pattern>/view</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>view</welcome-file> </welcome-file-list> <resource-ref> <description>DB Connection</description> <res-ref-name>db2</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>