Discussion:
Setting a Connection Timeout
(too old to reply)
Jared
2003-08-20 10:13:39 UTC
Permalink
Hello,

I need to specify to MS SQL Server with JDBC how long a connection
object (gotten by DriverManager.getConnection()) should be kept alive
before it times out. I've searched a fair bit, and all I can find is
Statement.setQueryTimeout() and DriverManager.setLoginTimeout(), which
are both not what I need.

Statement.setQueryTimeout() will cause a query that's taking too long
to execute to time out, and DriverManager.setLoginTimeout() will cause
a connection that is taking too long to be created to time out. But
how can I cause an idle connection that has been around too long to
close itself?

Any help would be appreciated!
Thanks, Jared Hagel
Joseph Weinstein
2003-08-20 14:53:48 UTC
Permalink
Hi. There is no standard JDBC API to do this job. A given DBMS may
have a configuration option to kill idle connections after a given time,
though the idle client won't find out about it until they try to use the
now-dead connection and find it's broken. You could always write
a connection-wrapper class that uses Java time-related functions to
close a JDBC connection when you want...
What do you mean by 'before it times out'? A JDBC connection
should be OK indefinitely... Ar you just finding connections have died
out from under you?
Joe
Post by Jared
Hello,
I need to specify to MS SQL Server with JDBC how long a connection
object (gotten by DriverManager.getConnection()) should be kept alive
before it times out. I've searched a fair bit, and all I can find is
Statement.setQueryTimeout() and DriverManager.setLoginTimeout(), which
are both not what I need.
Statement.setQueryTimeout() will cause a query that's taking too long
to execute to time out, and DriverManager.setLoginTimeout() will cause
a connection that is taking too long to be created to time out. But
how can I cause an idle connection that has been around too long to
close itself?
Any help would be appreciated!
Thanks, Jared Hagel
vaidas
2003-09-24 12:50:19 UTC
Permalink
Hi,

where can i find the configuration option for killing idle connections after
a given time on MS Sql Server 2000?

Vaidas
Post by Joseph Weinstein
Hi. There is no standard JDBC API to do this job. A given DBMS may
have a configuration option to kill idle connections after a given time,
though the idle client won't find out about it until they try to use the
now-dead connection and find it's broken. You could always write
a connection-wrapper class that uses Java time-related functions to
close a JDBC connection when you want...
What do you mean by 'before it times out'? A JDBC connection
should be OK indefinitely... Ar you just finding connections have died
out from under you?
Joe
Post by Jared
Hello,
I need to specify to MS SQL Server with JDBC how long a connection
object (gotten by DriverManager.getConnection()) should be kept alive
before it times out. I've searched a fair bit, and all I can find is
Statement.setQueryTimeout() and DriverManager.setLoginTimeout(), which
are both not what I need.
Statement.setQueryTimeout() will cause a query that's taking too long
to execute to time out, and DriverManager.setLoginTimeout() will cause
a connection that is taking too long to be created to time out. But
how can I cause an idle connection that has been around too long to
close itself?
Any help would be appreciated!
Thanks, Jared Hagel
Loading...