Problem with testing JSP against DB2

Issues and Questions related to running Apache Tomcat on z/OS
Post Reply
Michele Modolo
Posts: 10
Joined: Fri Feb 10, 2006 6:04 am

Problem with testing JSP against DB2

Post by Michele Modolo »

Hi all,

I found some clear JSP examples from IBM at the link http://www-306.ibm.com/software/webserv ... 0203a.html

In those examples (intended to be run within IBM Websphere Application Server) the tag to connect and query DB2 are:
<tsx:dbconnect id="conn" url="jdbc:db2:sample" driver="COM.ibm.db2.jdbc.app.DB2Driver">
<userid><tsx:getProperty name="request" property=request.getParameter("USERID") /></userid>
<passwd><tsx:getProperty name="request" property=request.getParameter("PASSWD") /></passwd>
</tsx:dbconnect>
.................
tsx:dbquery id="qs" connection="conn" >
select * from Employee where WORKDEPT= '<tsx:getProperty name="request" property=request.getParameter("WORKDEPT") />'
</tsx:dbquery>

I noticed that:
1) The driver used is COM.ibm.db2.jdbc.app.DB2Driver
2) No xml tag description file is provided
3) The JSL examples are intended to be run within IBM Websphere Application Server

So I thought that:
1) Ok, I got COM.ibm.db2.jdbc.app.DB2Driver driver within my system
2) Possibly <tsx: tag are included by default in IBM Websphere Application Server so they might not work within Tomcat

Well, I tried to port the example within Tomcat as reported in the following excerpt:
<H1><CENTER>Testing JSP on DB2</CENTER></H1>
<%
<tsx:dbconnect id="conn" url="jdbc:db2:D200"
driver="COM.ibm.db2.jdbc.app.DB2Driver">
<userid>MYUSERID</userid>
<passwd>MYPASSWORD</passwd>
</tsx:dbconnect>
%>
<%
<tsx:dbquery id="qs" connection="conn" >
SELECT PYT_PGP_TYPE,PYT_PGP_PRGR,PYT_PGP_PARM_TIPO
FROM YCSXCM.PYTCMPGP
WHERE PYT_PGP_TYPE LIKE 'BD%'
</tsx:dbquery>
%>
..........

I got these errors:
An error occurred at line: 7 in the jsp file: /xcm/kop.jsp
Generated servlet error:
/u/db00974/jakarta-tomcat-5.0.28/work/Catalina/localhost/_/org/apache/jsp/xcm/kop_jsp.java:49: illegal start of expression

An error occurred at line: 7 in the jsp file: /xcm/kop.jsp
Generated servlet error:
<tsx:dbconnect id="conn" url="jdbc:db2:D200"
^

An error occurred at line: 16 in the jsp file: /xcm/kop.jsp
Generated servlet error:
/u/db00974/jakarta-tomcat-5.0.28/work/Catalina/localhost/_/org/apache/jsp/xcm/kop_jsp.java:59: illegal start of expression
<tsx:dbquery id="qs" connection="conn" >
^

An error occurred at line: 16 in the jsp file: /xcm/kop.jsp
Generated servlet error:
/u/db00974/jakarta-tomcat-5.0.28/work/Catalina/localhost/_/org/apache/jsp/xcm/kop_jsp.java:62: unclosed character literal
WHERE PYT_PGP_TYPE LIKE 'BD%'
^

An error occurred at line: 16 in the jsp file: /xcm/kop.jsp
Generated servlet error:
/u/db00974/jakarta-tomcat-5.0.28/work/Catalina/localhost/_/org/apache/jsp/xcm/kop_jsp.java:62: illegal line end in character literal
WHERE PYT_PGP_TYPE LIKE 'BD%'
^

So I think that:
1) Jasper is correctly invoked and this is a positive thing
2) <tsx: is a built-in tag of IBM Websphere Application Server and it's not recognized within Tomcat
3) I think that it might be a Tomcat built-in tag equivalent to <tsx: but I don't know what it may be
4) I think that if no Tomcat built-in tag is provided an equivalent user tag could be implemented (and probably descripted in the application web.xml file) but I don't have any idea about how to do it in order to exploit COM.ibm.db2.jdbc.app.DB2Driver driver as simply as <tsx: tag does.

As usual any help will be highly appreciated!

Regards,
Michele
coz
Posts: 391
Joined: Fri Jul 30, 2004 5:29 pm

Post by coz »

Michele,

I don't know about the tag library that you are using, but you can get similar results with jstl. Here's a good link on the subject:

http://www.onjava.com/pub/a/onjava/2002 ... jstl2.html

You will need to get the jstl tag library and make it accessible to Tomcat, then in your web.xml add:

Code: Select all

<context-param>
<param-name>
  javax.servlet.jsp.jstl.sql.dataSource
</param-name>
<param-value>
  jdbc/Production
</param-value>
</context-param>
Where the JNDI datasource is the one you defined in your context to connect to DB2. Once this is set up, you can write code like this:

Code: Select all

<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>

<html>
<body>
  <h1>Reading database data</h1>
  <sql:query var="emps" sql="SELECT * FROM Employee" />
  ...
</body>
</html>
We are working on updated documentation for z/OS Tomcat DB2 connectivity, including the use of Apache's DBCP. Look for this in the near future.
Post Reply