Thread: JDBC/JSP: Strange Problem

JDBC/JSP: Strange Problem

From
"Scott Street"
Date:
Hi folks,  new to the list and PostgreSQL -- In the process of converting
all of my MySql programs to Postgres.

I have run into a strange problem I can't resolve,  I narrowed the problem
down to a small snippet of code below.

The code compiles and runs,  I see the select all * from messages execute
and the data is returned via the network, however, the jsp only outputs the
LAST record returned.   Can't figure it out -- anyone else hit this?

BTW:  Tomcat 3.3, Java 1.3.1, PostgreSQL 7.1.3 with JDBC 7.1-1.2.jar

(jsp code --- cut here ---)

<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<%@taglib uri="/WEB-INF/lib/dbtags.jar" prefix="jdbc" %>
<%@taglib uri="/WEB-INF/lib/ietags.jar" prefix="pr" %>
<body>
<H1>Message Listing from Dataserver</h1>
<jdbc:connection id="jdbcConn"
    driver="org.postgresql.Driver"
    url="jdbc:postgresql://ocean/bbs"
    user="bbs" password="******" />

<jdbc:query id="msgQuery" connection="jdbcConn" resultsId="msgDS"
resultsScope="session" >
    select all * from messages
</jdbc:query>
<TABLE border=1>
<TR>
    <TH>MsgId
    <TH>fromUser
    <TH>toUser
    <TH>Subject
    <TH>Flags
    <TH>Text
</TR>
<pr:iterator results="msgDS" >
<TR>
    <TD><pr:field name="msgid"/>
    <TD><pr:field name="fromuser"/>
    <TD><pr:field name="touser"/>
    <TD><pr:field name="subject"/>
    <TD><pr:field name="flags"/>
    <TD><pr:field name="msgtext"/>
</TR>
</pr:iterator>
</TABLE>


Re: JDBC/JSP: Strange Problem

From
"Nick Fankhauser"
Date:
Scott-

It's kinda' tough to tell what's happening from the code snippet because
most of the jdbc code is buried in the taglibs.

You mentioned converting from MySQL- have the taglibs been written
specifically for MySQL, or are they general-purpose libs?

I think If I were troubleshooting, I'd first look at the source for the
results in the browser just to make sure the data isn't being hidden because
of some bogus html, and then I'd look at the taglibs starting with ietags,
as that seems to be where the code that steps through your resultset lives.

If the taglibs aren't too huge, I'd like to take a look at them. It's a bit
off-topic for this list, but if you'd like a second pair of eyeballs staring
at them (and they aren't proprietary code), feel free to send the code for
the taglibs to me directly & I'll see if I notice anything obvious.

-Nick

--------------------------------------------------------------------------
Nick Fankhauser  nickf@ontko.com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services     http://www.ontko.com/



> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Scott Street
> Sent: Sunday, December 02, 2001 12:04 AM
> To: PostgreSQL JDBC List
> Subject: [JDBC] JDBC/JSP: Strange Problem
>
>
> Hi folks,  new to the list and PostgreSQL -- In the process of converting
> all of my MySql programs to Postgres.
>
> I have run into a strange problem I can't resolve,  I narrowed the problem
> down to a small snippet of code below.
>
> The code compiles and runs,  I see the select all * from messages execute
> and the data is returned via the network, however, the jsp only
> outputs the
> LAST record returned.   Can't figure it out -- anyone else hit this?
>
> BTW:  Tomcat 3.3, Java 1.3.1, PostgreSQL 7.1.3 with JDBC 7.1-1.2.jar
>
> (jsp code --- cut here ---)
>
> <%@page contentType="text/html"%>
> <html>
> <head><title>JSP Page</title></head>
> <%@taglib uri="/WEB-INF/lib/dbtags.jar" prefix="jdbc" %>
> <%@taglib uri="/WEB-INF/lib/ietags.jar" prefix="pr" %>
> <body>
> <H1>Message Listing from Dataserver</h1>
> <jdbc:connection id="jdbcConn"
>     driver="org.postgresql.Driver"
>     url="jdbc:postgresql://ocean/bbs"
>     user="bbs" password="******" />
>
> <jdbc:query id="msgQuery" connection="jdbcConn" resultsId="msgDS"
> resultsScope="session" >
>     select all * from messages
> </jdbc:query>
> <TABLE border=1>
> <TR>
>     <TH>MsgId
>     <TH>fromUser
>     <TH>toUser
>     <TH>Subject
>     <TH>Flags
>     <TH>Text
> </TR>
> <pr:iterator results="msgDS" >
> <TR>
>     <TD><pr:field name="msgid"/>
>     <TD><pr:field name="fromuser"/>
>     <TD><pr:field name="touser"/>
>     <TD><pr:field name="subject"/>
>     <TD><pr:field name="flags"/>
>     <TD><pr:field name="msgtext"/>
> </TR>
> </pr:iterator>
> </TABLE>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Re: JDBC/JSP: Strange Problem

From
"Dave Cramer"
Date:
Scott,

Nicks suggestion is essentially what we need to do to debug this. One
other way to debug this is to look at the servlet that was created by
the JSP compiler. You should have a work directory, and a number of
servlets in there. If you can find the servlet, and the relevant code
please post.

Dave

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Scott Street
Sent: Sunday, December 02, 2001 12:04 AM
To: PostgreSQL JDBC List
Subject: [JDBC] JDBC/JSP: Strange Problem


Hi folks,  new to the list and PostgreSQL -- In the process of
converting all of my MySql programs to Postgres.

I have run into a strange problem I can't resolve,  I narrowed the
problem down to a small snippet of code below.

The code compiles and runs,  I see the select all * from messages
execute and the data is returned via the network, however, the jsp only
outputs the
LAST record returned.   Can't figure it out -- anyone else hit this?

BTW:  Tomcat 3.3, Java 1.3.1, PostgreSQL 7.1.3 with JDBC 7.1-1.2.jar

(jsp code --- cut here ---)

<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<%@taglib uri="/WEB-INF/lib/dbtags.jar" prefix="jdbc" %> <%@taglib
uri="/WEB-INF/lib/ietags.jar" prefix="pr" %> <body> <H1>Message Listing
from Dataserver</h1> <jdbc:connection id="jdbcConn"
    driver="org.postgresql.Driver"
    url="jdbc:postgresql://ocean/bbs"
    user="bbs" password="******" />

<jdbc:query id="msgQuery" connection="jdbcConn" resultsId="msgDS"
resultsScope="session" >
    select all * from messages
</jdbc:query>
<TABLE border=1>
<TR>
    <TH>MsgId
    <TH>fromUser
    <TH>toUser
    <TH>Subject
    <TH>Flags
    <TH>Text
</TR>
<pr:iterator results="msgDS" >
<TR>
    <TD><pr:field name="msgid"/>
    <TD><pr:field name="fromuser"/>
    <TD><pr:field name="touser"/>
    <TD><pr:field name="subject"/>
    <TD><pr:field name="flags"/>
    <TD><pr:field name="msgtext"/>
</TR>
</pr:iterator>
</TABLE>


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



Re: JDBC/JSP: Strange Problem

From
"Nick Fankhauser"
Date:

> You should have a work directory, and a number of
> servlets in there. If you can find the servlet, and the relevant code
> please post.

That's an excellent idea- on our system (Debian 2.4, tomcat 3.2) the work
directory is /usr/share/tomcat/work/. In the work directory is a directory
for each context & in there will be the servlet code for each jsp. The
filenames are pretty long, but the jsp file name is imbedded in them so you
can tell which one you need.

-Nick


Re: JDBC/JSP: Strange Problem

From
Jens Carlberg
Date:
<snip>
> <TR>
>     <TH>MsgId
>     <TH>fromUser
>     <TH>toUser
>     <TH>Subject
>     <TH>Flags
>     <TH>Text
> </TR>
> <pr:iterator results="msgDS" >
> <TR>
>     <TD><pr:field name="msgid"/>
>     <TD><pr:field name="fromuser"/>
>     <TD><pr:field name="touser"/>
>     <TD><pr:field name="subject"/>
>     <TD><pr:field name="flags"/>
>     <TD><pr:field name="msgtext"/>
> </TR>
> </pr:iterator>
> </TABLE>

A bit of topic, but... You're not closing <TH> and <TD>. It's not
required in HTML 3.2, but it actually is in 4.0. So, you could possibly
have some side effects you haven't counted on.

However, it's easy enough to spot; check the page source and see if it
contains all your data. If it does, it's the rendering. If not, it's the
taglib. Not much else that can go wrong. :-)

///Jens Carlberg