Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
JITL: The Managed Database Job
Info | ||
---|---|---|
| ||
This job uses the deprecated sos.scheduler.managed.JobSchedulerManagedDatabaseJob that has been deprecated with Release 1.12. The JobSchedulerManagedDatabaseJobSOSHibernate job is provided as an alternative. |
This job is used as a standalone solution to execute (SQL-)statements in a database and can be used standalone or triggered by orders to execute statements in a database.
These can be - i.e. as an order job.
It can execute database procedures or SQL statements.
(A general overview of all JITL jobs can be found Library of Standard Jobs - JITL).
The description JobSchedulerManagedDatabaseJob.xml is stored in the ./jobs directory of your Job Scheduler the JobScheduler installation.
The SQL instructions are written in the command parameter.
It is possible to define more than one instruction in the command parameter.
Such instructions are then carried out in the order in which they are written and must be separated by a semicolon and a subsequent new line.
The Managed Jobs PHP web interface provides a textarea for this, while in the Job Scheduler Object Editor (JOE), only an input field is available.
PHP converts the textarea hexadecimal because a newline cannot be written in an XML attribute (see also Why_have_the_command_parameter_of_some_jobs_a_hexadecimal_coded_value%3F).
If you want to use the job with multiple statements without the Managed Jobs, then the statements should be changed hexadecimal or you use You can use
as newline.
The following is an example of a job chain in which the command contains two statements separated by
.
The job chain launchDB.job_chain.xml:
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job_chain.xml job_chain] <job_chain orders_recoverable="yes" visible="yes"> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job<job_chain_node.xml job_chain_node] state="launch" job="launchDB" next_state="success" error_state="error"/> <job_chain_node state="success"/> <job_chain_node state="error"/> </job_chain> |
The order launchDB,updateMyTable.order.xml:
It contains an update statement and a commit. The value of the statement_newline parameter is used as separator.
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/order.xml order] <order title="update MY_TABLE"> <params> <param name="command" value="update MY_TABLE set a='foo' where b='bar';&#10;commit;"/> </params> <run_time/> </order> |
The job launchDB.job.xml:
(i.e. with a MySQL database connection, examples for other DBMS see below): It executes the statements where the statement in the order command parameter overwrites the statement in the job command parameter.
MySQL (MariaDB)
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job] <job title="Launch Database Statement" order="yes" stop_on_error="no"> <description> <include file="jobs/JobSchedulerManagedDatabaseJob.xml"/> </description> <params> <param name="db_class" value="SOSMySQLConnection"/> <param name="db_driver" value="com.mysql.jdbc.Driver"/> <param name="db_url" value="jdbc:mysql://localhost:3306/scheduler"/> <param name="db_user" value="scheduler"/> <param name="db_password" value="scheduler"/> <param name="command" value=""/> </params> <script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/> <run_time/> </job> |
If you prefer a shell solution, then you need only one (standalone) job and a database client:
For other database management systems you have to modify the connection parameter like in the following examples:
MS SQL Server
Code Block |
---|
<job |
Code Block |
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job] title="Launch Database Statement" order="yes" stop_on_error="no"> <description> <include file="jobs/JobSchedulerManagedDatabaseJob.xml"/> </description> <params> <param name="statementdb_newlineclass" value="__x0A__SOSMSSQLConnection"/> <param name="statementsdb_driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/> value="update MY_TABLE set a='foo' where b='bar';__x0A__commit;"/> <param name="db_url" value="jdbc:sqlserver://localhost:1433;sendStringParametersAsUnicode=false;selectMethod=cursor;databaseName=scheduler"/> <param name="db_user" value="scheduler"/> <param name="db_password" value="scheduler"/> <param name="command" value=""/> </params> <script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/> <run_time/> </job> |
Oracle
Code Block |
---|
<job title="Launch Database Statement" order="yes" stop_on_error="no"> <description> <include file="jobs/JobSchedulerManagedDatabaseJob.xml"/> </description> <params> <param name="db_userclass" value="SOSOracleConnection"/> <param name="db_driver" value="scheduleroracle.jdbc.driver.OracleDriver"/> <param name="db_password"url" value="jdbc:oracle:thin:@localhost:1521:scheduler"/> <param name="db_user" value="scheduler"/> <param name="db_password" </params> value="scheduler"/> <script<param languagename="shell"> command" value=""/> <![CDATA[ echo $SCHEDULER_PARAM_STATEMENTS | sed -e 's/'$SCHEDULER_PARAM_STATEMENT_NEWLINE'/\n/g' > myupdate.sql mysql -u$SCHEDULER_PARAM_DB_USER -p$SCHEDULER_PARAM_DB_PASSWORD $SCHEDULER_PARAM_DB < myupdate.sql mysqlErr=$? rm myupdate.sql exit $mysqlErr ]]> </script> <run_time/> </job> </params> <script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/> <run_time> </job> |
See also:
PostgreSQL
Code Block |
---|
<job title="Launch Database Statement" order="yes" stop_on_error="no">
<description>
<include file="jobs/JobSchedulerManagedDatabaseJob.xml"/>
</description>
<params>
<param name="db_class" value="SOSPgSQLConnection"/>
<param name="db_driver" value="org.postgresql.Driver"/>
<param name="db_url" value="jdbc:postgresql://localhost:5432/scheduler"/>
<param name="db_user" value="scheduler"/>
<param name="db_password" value="scheduler"/>
<param name="command" value=""/>
</params>
<script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/>
<run_time>
</job>
|
IBM/DB2
Code Block |
---|
<job title="Launch Database Statement" order="yes" stop_on_error="no">
<description>
<include file="jobs/JobSchedulerManagedDatabaseJob.xml"/>
</description>
<params>
<param name="db_class" value="SOSDB2Connection"/>
<param name="db_driver" value="com.ibm.db2.jcc.DB2Driver"/>
<param name="db_url" value="jdbc:db2://localhost:50000/scheduler:driverType=2;retrieveMessagesFromServerOnGetMessage=true;"/>
<param name="db_user" value="scheduler"/>
<param name="db_password" value="scheduler"/>
<param name="command" value=""/>
</params>
<script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedDatabaseJob"/>
<run_time>
</job>
|