Re: Database reset connection - Mailing list pgsql-jdbc

From rob stone
Subject Re: Database reset connection
Date
Msg-id 1480508922.5197.0.camel@gmail.com
Whole thread Raw
In response to Database reset connection  (Manoj Palhade <reply.manoj@gmail.com>)
Responses Re: Database reset connection
Re: Database reset connection
List pgsql-jdbc
On Wed, 2016-11-30 at 16:48 +0530, Manoj Palhade wrote:
> Hi,
>
> I have Java class which implements the Database(Postgres) related
> functionality.
>
> The problem is if Database stopped and then restart then My this
> class throws SQLException as connection got reset(database is up and
> running).
>
> Is there any way that after Database restarted; my class
> automatically Connection to database and work as expected instead of
> throwing SQLException.
>
> Is there anyway with Properties as a parameter to
> DriverManager.getConnection().
>
> Thanks and Regards,
>
> Manoj Palhade
>



From the javdoc's:-

 isValid

boolean isValid(int timeout)
                throws SQLException

    Returns true if the connection has not been closed and is still
valid. The driver shall submit a query on the connection or use some
other mechanism that positively verifies the connection is still valid
when this method is called.

    The query submitted by the driver to validate the connection shall
be executed in the context of the current transaction.

    Parameters:
        timeout - - The time in seconds to wait for the database
operation used to validate the connection to complete. If the timeout
period expires before the operation completes, this method returns
false. A value of 0 indicates a timeout is not applied to the database
operation.

    Returns:
        true if the connection is valid, false otherwise 
    Throws:
        SQLException - if the value supplied for timeout is less then 0
    Since:
        1.6

    See Also:
        DatabaseMetaData.getClientInfoProperties()



pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Database reset connection
Next
From: Manoj Palhade
Date:
Subject: Database reset connection