| Author |
How to check whether time out occured
|
vignesh bala
Greenhorn
Joined: Aug 19, 2006
Posts: 28
|
|
Hi all, I have a small problem.my need is I have to query a database and wait for 15 seconds(timeout value). If time out occurs, then i have to again issue the same query (with same 15 seconds as timeout).I must repeat this process 4 times(if in case every query fails due to some reason). My doubt is how I can check whether there is a timeout or any other issue.It is given as it will throw a SQLException when timeout occurs but SQLException can occur due to other causes also. Can anyone suggest some way of doing this. Regards, Vignesh
|
 |
Purushoth Thambu
Ranch Hand
Joined: May 24, 2003
Posts: 425
|
|
|
In general the SQLException's errorCode property must be populated with timeout error code. Call getErrorCode() method on the SQLException and process the error code. Are you using SQLServer?
|
 |
vignesh bala
Greenhorn
Joined: Aug 19, 2006
Posts: 28
|
|
Hi, No I am using DB2 on mainframe(AS400). Is this error code specific to driver or data base?I am using AS400JdbcDriver. Thanks & Regards, Vignesh
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
You'd have to spawn a separate thread that queries the database. Once its finished querying the database it populates some output string/object/boolean. You main thread would just wait 15 seconds and if doesn't see this output object populated, would kill the thread and create a new one.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Purushoth Thambu
Ranch Hand
Joined: May 24, 2003
Posts: 425
|
|
Vignesh, The error codes are specific to database. Drivers on their own can't generate DB error codes. So you can safely rely on the SQLException error_code's. Scott, I am not sure what you are suggesting is good approach. Spawing a thread is one thing, but terminating a thread will be difficult.
|
 |
vignesh bala
Greenhorn
Joined: Aug 19, 2006
Posts: 28
|
|
ya Purushothaman, I Checked with the error codes and using it as my checking criteria. Thanks. Scott, I also considerd your approch but using multiple threads requires some work and has some dependencies in my application. So I am unable to do it sucessfully.Thanks a lot for your sugession
|
 |
 |
|
|
subject: How to check whether time out occured
|
|
|