Reputation: 471
I'm using ODP
on my Oracle DB application.I registered to OracleConnection.StateChange
event for watching the state of the connection. When i disconnect the db connection the event fires but for example if the internet connection is lost there is no action.
How can i handle these kind of(internet conenction lost etc.) situations via the StateChange
event?
Or do i have to create a thread for checking the connnection state
regularly?
If yes how can i check the connection because i checked the state and it seems to be open even i unplug the internet cable.
Regards.
Upvotes: 1
Views: 1169
Reputation: 5614
The common way is to issue an unexpensive sql statement just before the connection is used for something. On oracle it is something like 'select 1 from dual', on ms-sql 'select 1'. This sql forces a roundtrip to the server and lost connection to the server is reported.
JBoss is using something called check-valid-connection-sql. Others have other names.
Upvotes: 2