Monday, July 12, 2010

Updating an existing Trans-SQL Job's interval programmatically

The title itself suggests that the topic about to be discussed now has very little thing to do with Java, but this is something that any Java programmer needs to know when they are working along with SQL Server database.

Let’s look at the scenario now, let’s say you have created a Trans-SQL JOB to run a particular process periodically, but you want to provide the feasibility for the users to change the frequency to run the Trans-SQL JOB from your Java application itself. Now how is that possible? Ya, that’s what we are about to explore now, how to change the frequency from the Java application itself.
First create a JDBC connection as shown below
Once you have created the Connection class, make use of it in the main class to establish the connection with the Database. Create a callable statement where you will call the SQL Server System stored procedure called “sp_update_schedule”. Take note that the parameters assigned below are mandatory parameters for the said Stored Procedure. If you look at the code below, the value of the “schedule_id” is assigned to “10” and “name” is assigned to “null”. This is because either 1 value only should be initialized for “sp_update_schedule” to identify the schedule need to be updated.
For further reference about “sp_update_schedule”, please refer to: http://msdn.microsoft.com/en-us/library/ms187354.aspx

Author: Thiagu

No comments:

Post a Comment