Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check whether time out occured

 
vignesh bala
Greenhorn
Posts: 28
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic