Re: JDBC Driver Class: Connection Method: isClosed() error

From: Peter T Mount <peter(at)retep(dot)org(dot)uk>
To: Oscar FRANCOIS <ofrancois(at)e-contact(dot)fr>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: JDBC Driver Class: Connection Method: isClosed() error
Date: 2001-04-27 13:53:15
Message-ID: 988379595.3ae979cb850be@webmail.retep.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Quoting Oscar FRANCOIS <ofrancois(at)e-contact(dot)fr>:

> Hi,
>
> Here are the maximum information about the error:
>
> OS where the class is running: winnt4 with jdk1.3
> DB OS: Linux Debian potatoe
> Postgresql version: 7.0.3
> Driver JDBC: included in the source code.
>
> Description:
> -----------
> First case (postmaster is running ok):
> I get the connection with:
> conn = DriverManager.getConnection("...
> I do a sleep for 5 seconds
> I test the code with the isClosed() function.
> I do a request like "select * from ...."
> Finally I close the connection.
>
> But If I do the following:
> I get the connection with:
> conn = DriverManager.getConnection("...
> I do a sleep for 5 seconds
> (during while I stop the postmaster)
> I test the code with the isClosed() function.
> ---> WHICH RETURN FALSE!!! <-----
> I do a request like "select * from ...."
> ---> which generate a SQLException Error <---
> Finally I close the connection.
> ---> which generate a SQLException Error <---
>
> Why the Hell, does the method isclosed() is answering that everything
> is Ok whereas the postmaster
> is closed & the next request generate an Error.

First check: http://jdbc.postgresql.org/clarify/Connection.html#isClosed

This describes how isClosed() is supposed to work as per the JDBC
Specifications.

In it, you'll notice that before closed() is called, the result of isClosed()
is undetermined. Strange but true. So technically you can't call isClosed()
before close().

Prior to 7.1, isClosed() simply returned true if it had a PG_Stream object,
hence you got true even though the actual connection wasn't there.

As of PostgreSQL 7.1, isClosed() sort of goes against the specs, and does the
correct thing by returning true only if the connection is valid (does this by
first checking to see if it has a connection (as before), then by sending a
dummy query to the backend).

Goes against the specs, but one of those that makes more sense without really
breaking things.

Peter

--
Peter Mount peter(at)retep(dot)org(dot)uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Lockhart 2001-04-27 16:04:34 Re: 7.1 euro-style dates insert error
Previous Message Victor Wagner 2001-04-27 13:27:47 Invalid outer joins with subquery