This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling a database shutdown within java

 
Chad Naber
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

I am writing a really simple java application that is meant to act like a daemon. Basically it queries a database constantly, and sends the results to a stored procedure.

So, my question is this: Since my java code needs to run constantly, how can I get it to handle database restarts successfully? Is there a method I can invoke that will handle this, or am I going to have to do some nifty work in the catch?

Here is a snippet of the code I am using. Please don't laugh, I am pretty new at this java stuff. Also, any constructive criticism is highly welcome:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chad,
It would have to be a bit more involved than that. If the database is starting, a SQL Exception will get thrown. Something within the loop needs to handle this condition and sleep until the next attempt.
 
Chad Naber
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne! You sent me on the right path, and now I have a daemon that handles database shutdowns. For those interested, here is how I did it:

1. Have a try catch around the majority of the method to handle any crazy errors.
2. Have a nested try catch within the portion that is looping, that handles any SQL exceptions.

My original problem was that I only had 1 try catch block that was outside of the while loop, so in handling exceptions it exited the loop.
 
Alan Christen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chad,

I know this does not answer your question but why using Java?

Did you know you can do the same in a shell script with a *lot* less code?

I did it for Oracle & DB2 without too much trouble....you can check web sites like this one

http://www.orafaq.com/scripts

My 2 cents.

Al.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic