Can you recreate the behavior outside of ServletExec? With a straight Java
app? (If you can, just add a main() to the code that executes this snippet
and run it.)
I normally hate people who suggest this, but it *might* be a bug in the
driver implementation. I'd be surprised if it is, but your JDBC code looks
fine to me, and I can't imagine what effect running it in a servlet would
have to cause this.
The only other thing I'd check is to make sure db still exists and is
prepared when the second call comes around; perhaps it gets reallocated
somewhere?
Ted Neward
Patterns/C++/Java/CORBA/EJB/COM-DCOM spoken here
http://www.javageeks.com/~tneward
"I don't even speak for myself; my wife won't let me." --Me
-----Original Message-----
From: Rik Gammack <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Wednesday, June 16, 1999 6:12 AM
Subject: Invalid state for getResultSet
>Does anyone know a work-around for this when I run a servlet under
ServletExec.... I've contacted ServletExec themselves, but no reply so far
and I'm on a tight schedule.
>
>I'm using JDBC to access a database. I have a PreparedStatement of "select
x from y where ?" and I'm using the setString method to fill in the
parameter as required. It all works okay the first time I call the
executeQuery method. I close the resultSet, go off and do some other queries
(once each) and finally come back to execute this query again. I set it up
with the new parameter, execute the query, and it throws an SQLException
"Invalid state for getResultSet".
>
>It doesn't seem to matter which of the PreparedStatements in the servlet
get executed twice, the second time throws an Exception.
>
>Everything works perfectly when I run the same servlet under the Java Web
Server. (Same machine, same ODBC connection etc). Short of actually
switching to the JWS (our clients have just gone out and bought ServletExec,
so this would not be a politically sound suggestion) what can I do?
>
>Many thanks,
>Rik Gammack.
>
>The code snippet looks like ...
> pGetProjectDetails = db.prepareStatement(
> "select c.Name, pvp.Project_Title, "
> + "pvp.Customer, pvp.Department_Code,
pvp.Project_Code "
> + "from ProtemisProject pvp, "
> + " Customer c "
> + "where pvp.Project_Ref = ? "
> + "and pvp.Customer = c.No_ ");
>
>
//--------------------------------------------------------------------
>
> protected void getProjectDetails(TimeSheetEntry entry) throws
TimeSheetException
> {
> debug("getProjectDetails() - entry");
>
> entry.setFileName("");
>
> ResultSet results = null;
>
> try
> {
> pGetProjectDetails.setString(1,
entry.getFileNumber());
>
> results = pGetProjectDetails.executeQuery();
<<<<<<<<<<<<<<<<<<<< ERROR POINT
>
> if (results.next())
> {
> entry.setFileName(results.getString(1));
>
> /*
> ** Only insert the description if it hasn't
already
> ** been entered.
> */
> if (entry.getFileDescription().equals(""))
>
entry.setFileDescription(results.getString(2));
>
> entry.customer = results.getString(3);
> entry.deptCode = results.getString(4);
> if (entry.deptCode == null)
> entry.deptCode = "";
> entry.projectCode = results.getString(5);
> if (entry.projectCode == null)
> entry.projectCode = "";
> }
> else
> {
> throw new TimeSheetException("File Number
'" + entry.getFileNumber()
> + "' is not recognised.");
> }
> }
> catch (SQLException e)
> {
> debug("Error validating File Number '"
> + entry.getFileNumber() + "'.
because '" + e.getMessage() + "'");
> throw new TimeSheetException("Error validating File
Number '"
> + entry.getFileNumber() + "'.");
> }
> finally
> {
> if (results != null)
> {
> try
> {
> results.close();
> }
> catch (Exception e)
> {
> debug("Error closing results
because '" + e.getMessage() + "'");
> }
> }
> }
> }
>
//--------------------------------------------------------------------
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html