• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing and waiting for Sql job to finish.

 
Anshuman Chakraborty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to execute an SQL job using PreparedStatement which went sucessful.

The problem is, I want my program to wait untill my SQL job finishes.
I am able to achieve this using try/catch and recursion.But i am not satisfied with it.
The logic goes like this
1. Call the job and wait for few seconds.
2. Using recursion call the method again. This time it throws an exception since the job is already running.
3. In the catch block wait again for few seconds and call the method (recursion).
4. Once the job is successfully fininshed come out of the method.



I know there is a better way to achieve this.

Please help !!!.











 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is SQL Server, yes? in which case you could use sp_help_job to watch the running job's status. You'd still need to poll this, but at least you would no longer be using exceptions to implement your logic.
 
Anshuman Chakraborty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much paul.

Yes, this is Microsoft SQL Server. Now the approach is much cleaner.

Thank you once again. Appreciate your help.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic