由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - jdbc connection timeout ?
相关主题
请问JDBC连SQL server的connect reset问题如何解决? (转载)override/overload/overwrite in Java
Re: JDBC access Oracle?? & Connection PoolingJava代码,老是compile出错,大家帮我看看哪错了。。。
[转载] Db2 里设置通信时TCP/IP的端口和远端用JDBC问题What's the relationship between Enterprise JavaBe
jdbc连接数据库出现的问题JSP for the ASP Developer
jdbc问题一问Re: question about interface.(也许是答案)
请教一个关于JDBC的问题,实在太烦了!how to change the input mode?
[合集] Connection Pooling.How to connect to SQL2000?
jdbc + oracle connection pooling问题用java画直线的问题
相关话题的讨论汇总
话题: connection话题: reconnect话题: pool话题: jdbc话题: timeout
进入Java版参与讨论
1 (共1页)
h**********c
发帖数: 4120
1
the question:
Sun has a jdbc pool example. I implement the interfaces.
The connections time out overnight.
It is not recommended to use auto-reconnect. why? the key point is I don't
know how to set auto-reconnect.
Or there is better solution.
Put simple,
how to check java.sql.connection valid? It is has abstract function isValid,
but how to overwrite it? if not valid, how to reconnect?
Thanks in advance.
b******y
发帖数: 9224
2
you could do a "ping" using sql, say, "select 1". If it throws exception,
that means the connection is dead.
It is like checking heartbeat...
h**********c
发帖数: 4120
3
I once google that somebody suggest using getMetadata (don't recall the
exact fucntion name).
I met the situation that a connection pass the getMetadata validation but
still throws exception when executing a statement.
The mysql server timeout connections at about ten hours, so it is very
difficult to find out where SQLException is thrown.
Very long code.
My temporary solution is when reaping the pool, if a connection idles more
than one hour remove it from the pool. So when try to get a connection from
the pool, we will not get a very old connection idled a very long time.
So to speak, if a pool is busy, the connections will not timeout. If the
pool is not busy, then empty the pool, start new connection when
getConnection is called. I have to wait till tomorrow to see it works or not.

【在 b******y 的大作中提到】
: you could do a "ping" using sql, say, "select 1". If it throws exception,
: that means the connection is dead.
: It is like checking heartbeat...

b******y
发帖数: 9224
4

from
Yes, I read about the metadata solution too somewhere before.
Anyhow, the solution I have above using "select 1" works like a charm for us
.

【在 h**********c 的大作中提到】
: I once google that somebody suggest using getMetadata (don't recall the
: exact fucntion name).
: I met the situation that a connection pass the getMetadata validation but
: still throws exception when executing a statement.
: The mysql server timeout connections at about ten hours, so it is very
: difficult to find out where SQLException is thrown.
: Very long code.
: My temporary solution is when reaping the pool, if a connection idles more
: than one hour remove it from the pool. So when try to get a connection from
: the pool, we will not get a very old connection idled a very long time.

g*****g
发帖数: 34805
5
Connection pool is actually a pretty complicated topic.
If this is for work, I suggest you use a 3rd party library,
e.g. DBCP

isValid,

【在 h**********c 的大作中提到】
: the question:
: Sun has a jdbc pool example. I implement the interfaces.
: The connections time out overnight.
: It is not recommended to use auto-reconnect. why? the key point is I don't
: know how to set auto-reconnect.
: Or there is better solution.
: Put simple,
: how to check java.sql.connection valid? It is has abstract function isValid,
: but how to overwrite it? if not valid, how to reconnect?
: Thanks in advance.

b******y
发帖数: 9224
6

We are using DBCP.
Actually, anybody educate me why Sun Microsystem or Oracle couldn't come up
with these amazing tools?

【在 g*****g 的大作中提到】
: Connection pool is actually a pretty complicated topic.
: If this is for work, I suggest you use a 3rd party library,
: e.g. DBCP
:
: isValid,

h**********c
发帖数: 4120
7
Empty the pool can solve the problem.
I quick-glanced DBCP not saw topics about time-out.Try later.
Thanks for replies!
B*****g
发帖数: 34098
8
No profit?

up

【在 b******y 的大作中提到】
:
: We are using DBCP.
: Actually, anybody educate me why Sun Microsystem or Oracle couldn't come up
: with these amazing tools?

b******y
发帖数: 9224
9

hmm, I guess you are right. As a company, probably no incentive to maintain
open source projects...

【在 B*****g 的大作中提到】
: No profit?
:
: up

h**********c
发帖数: 4120
10
apache 好像有很多ibm 的人在里面zt.

【在 B*****g 的大作中提到】
: No profit?
:
: up

1 (共1页)
进入Java版参与讨论
相关主题
用java画直线的问题jdbc问题一问
Sun Microsystem交易代号要从SUNW改为JAVA了请教一个关于JDBC的问题,实在太烦了!
关于 connectionPool 和 dataSource 的问题[合集] Connection Pooling.
Socket Connection refused in high-loaded serversjdbc + oracle connection pooling问题
请问JDBC连SQL server的connect reset问题如何解决? (转载)override/overload/overwrite in Java
Re: JDBC access Oracle?? & Connection PoolingJava代码,老是compile出错,大家帮我看看哪错了。。。
[转载] Db2 里设置通信时TCP/IP的端口和远端用JDBC问题What's the relationship between Enterprise JavaBe
jdbc连接数据库出现的问题JSP for the ASP Developer
相关话题的讨论汇总
话题: connection话题: reconnect话题: pool话题: jdbc话题: timeout