pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedDatabase reset connection
6+ messages / 4 participants
[nested] [flat]
* Database reset connection
@ 2016-11-30 11:18 Manoj Palhade <reply.manoj@gmail.com>
2016-11-30 12:20 ` Re: Database reset connection Dave Cramer <pg@fastcrypt.com>
2016-11-30 12:28 ` Re: Database reset connection rob stone <floriparob@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Manoj Palhade @ 2016-11-30 11:18 UTC (permalink / raw)
To: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Database reset connection
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
@ 2016-11-30 12:20 ` Dave Cramer <pg@fastcrypt.com>
1 sibling, 0 replies; 6+ messages in thread
From: Dave Cramer @ 2016-11-30 12:20 UTC (permalink / raw)
To: Manoj Palhade <reply.manoj@gmail.com>; +Cc: pgsql-jdbc
On 30 November 2016 at 06:18, Manoj Palhade <reply.manoj@gmail.com> 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
>
>
It really isn't that simple. What happens if the database never comes back?
This is why the application has to handle this. It should be trivial for
you write a wrapper that retries intelligently to reconnect.
Regards,
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Database reset connection
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
@ 2016-11-30 12:28 ` rob stone <floriparob@gmail.com>
2016-12-01 05:30 ` Re: Database reset connection Manoj Palhade <reply.manoj@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: rob stone @ 2016-11-30 12:28 UTC (permalink / raw)
To: Manoj Palhade <reply.manoj@gmail.com>; 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
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Database reset connection
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
2016-11-30 12:28 ` Re: Database reset connection rob stone <floriparob@gmail.com>
@ 2016-12-01 05:30 ` Manoj Palhade <reply.manoj@gmail.com>
2016-12-01 11:40 ` Re: Database reset connection Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 6+ messages in thread
From: Manoj Palhade @ 2016-12-01 05:30 UTC (permalink / raw)
To: rob stone <floriparob@gmail.com>; +Cc: pgsql-jdbc
Hi,
Thanks for your quick reply.
It looks like I am using JDBC3 from the runtime exception I got
(Caused by: java.lang.AbstractMethodError:
org.postgresql.jdbc3.Jdbc3Connection.isValid(I)Z)
I guess *postgresql.jdbc3* does not have any way to auto Connection to
database with timer.
Thanks and Regards,
Manoj Palhade
On Wed, Nov 30, 2016 at 5:58 PM, rob stone <floriparob@gmail.com> wrote:
>
> 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()
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Database reset connection
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
2016-11-30 12:28 ` Re: Database reset connection rob stone <floriparob@gmail.com>
2016-12-01 05:30 ` Re: Database reset connection Manoj Palhade <reply.manoj@gmail.com>
@ 2016-12-01 11:40 ` Dave Cramer <pg@fastcrypt.com>
2016-12-01 11:55 ` Re: Database reset connection Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Dave Cramer @ 2016-12-01 11:40 UTC (permalink / raw)
To: Manoj Palhade <reply.manoj@gmail.com>; +Cc: rob stone <floriparob@gmail.com>; pgsql-jdbc
No, as I said this is out of the scope of JDBC
Dave Cramer
davec@postgresintl.com
www.postgresintl.com
On 1 December 2016 at 00:30, Manoj Palhade <reply.manoj@gmail.com> wrote:
> Hi,
>
> Thanks for your quick reply.
>
> It looks like I am using JDBC3 from the runtime exception I got
> (Caused by: java.lang.AbstractMethodError: org.postgresql.jdbc3.
> Jdbc3Connection.isValid(I)Z)
>
> I guess *postgresql.jdbc3* does not have any way to auto Connection to
> database with timer.
>
>
>
> Thanks and Regards,
> Manoj Palhade
>
>
> On Wed, Nov 30, 2016 at 5:58 PM, rob stone <floriparob@gmail.com> wrote:
>
>>
>> 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()
>>
>>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Database reset connection
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
2016-11-30 12:28 ` Re: Database reset connection rob stone <floriparob@gmail.com>
2016-12-01 05:30 ` Re: Database reset connection Manoj Palhade <reply.manoj@gmail.com>
2016-12-01 11:40 ` Re: Database reset connection Dave Cramer <pg@fastcrypt.com>
@ 2016-12-01 11:55 ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Vladimir Sitnikov @ 2016-12-01 11:55 UTC (permalink / raw)
To: Manoj Palhade <reply.manoj@gmail.com>; +Cc: rob stone <floriparob@gmail.com>; Dave Cramer <pg@fastcrypt.com>; pgsql-jdbc
Manoj,
I would recommend:
1) Upgrade pgjdbc to a recent version
2) Ensure you do not have multiple pgjdbc jars on the classpath
3) Use a decent connection pool. For instance, HikariCP:
https://github.com/brettwooldridge/HikariCP
Hikari performs connection validation automatically, so the application
would receive validated connections only.
Vladimir
чт, 1 дек. 2016 г. в 14:41, Dave Cramer <pg@fastcrypt.com>:
> No, as I said this is out of the scope of JDBC
>
> Dave Cramer
>
> davec@postgresintl.com
> www.postgresintl.com
>
> On 1 December 2016 at 00:30, Manoj Palhade <reply.manoj@gmail.com> wrote:
>
> Hi,
>
> Thanks for your quick reply.
>
> It looks like I am using JDBC3 from the runtime exception I got
> (Caused by: java.lang.AbstractMethodError:
> org.postgresql.jdbc3.Jdbc3Connection.isValid(I)Z)
>
> I guess *postgresql.jdbc3* does not have any way to auto Connection to
> database with timer.
>
>
>
> Thanks and Regards,
> Manoj Palhade
>
>
> On Wed, Nov 30, 2016 at 5:58 PM, rob stone <floriparob@gmail.com> wrote:
>
>
> 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()
>
>
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2016-12-01 11:55 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-11-30 11:18 Database reset connection Manoj Palhade <reply.manoj@gmail.com>
2016-11-30 12:20 ` Dave Cramer <pg@fastcrypt.com>
2016-11-30 12:28 ` rob stone <floriparob@gmail.com>
2016-12-01 05:30 ` Manoj Palhade <reply.manoj@gmail.com>
2016-12-01 11:40 ` Dave Cramer <pg@fastcrypt.com>
2016-12-01 11:55 ` Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox