It looks that the problem is in the way you check whether query returned
results:
--cut---
if (stmt1.executeQuery().getFetchSize() == 0) {
                throw new ServletException("class is invalid: class = " +
request.getParameter("class"));
--cut---
fetchSize is only a "hint" for the JDBC driver as to how many records should
it fetch from a database. It does not tell you actual number of records
returned from your query.
You servlet fails when there is no records for a given combination of "id"
and "class" parameters

To check if query returned any records simply use:
if (results.next()){
  ....write image to output
}else{
//no records found
}

If there is no image for a given combination "id" and "class" you should
probably returne 404 status code to the client instead of throwing an
exception.
Check you access logs to see which requests are causing those errors.
Regards,
Adam


----- Original Message -----
From: "Matthew Kennedy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, March 10, 2002 3:49 AM
Subject: image from database servlet problem -- pooling issue?


> I am seeing strange behaviour with a servlet I wrote to return an image
> from a database table. I'm not sure if it's struts related or not, but I
> am relying on a datasource defined in the struts-config.xml. It might be
> a silly mistake in the servlet code itself even.
>
> I've attached the struts-config.xml which shows my datasource
> definition, the web.xml where I define the servlet and provide an
> initialization parameter, the servlet code (PhotoServlet.java) and a
> simple test.jsp page.
>
> The code I have seems to work most of the time (about 25/30 requests)
> before failing a couple of times. The log.txt attachment shows the
> result of doing:
>
>    while true
>    do
>      lwp-request \
>      'http://localhost:8080/shona/servlets/photo?id=1&class=thumbnail' \
>      | wc -c
>    done
>
> (just sequential requests)
>
> The error.txt attachment shows the exception information generated when
> a request fails. Note there seem to be two types of exceptions occuring
> here: a low level jdbc error, and a "no results returned" error.
>
> I've played with the maxCount and minCount parameters in the struts
> datasource definition. Same results, except in the case of several
> simultaneous requests to the servlet -- in which case raising maxCount
> seems to prolong the interval between exceptions.
>
> It's really been baffling me for a while now. What could be going wrong?
> Am I seeing a limitation of Struts' connection pool perhaps? Even if
> it's not struts related, suggestions would still be very welcome.
>
> Matt
>


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to