In the past, the database connection was always directly set in the Ktr file. Because the database connection address is often changed, I wanted to read the database connection through XML, modify the XML file directly when changing the database connection.
Here is how my Database connects to the XML file database. XML (in the Oracle column ):
<? XML version = "1.0" encoding = "UTF-8" standalone = "no"?>
<Database>
<URL> JDBC: oracle: thin: @ 192.168.1.100: 1521: orcl </URL>
<Classname> oracle. JDBC. Driver. oracledriver </classname>
<Username> test </username>
& Lt; password & gt; 123456 & lt;/password & gt;
</Database>
Then read the XML file. when reading the XML file, pay attention to the Data Type:
Set the environment variable setvariable. Ktr Source Code as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Transformation>
<Info>
<Name> setvariable </Name>
<Description/>
<Extended_description/>
<Trans_version/>
<Trans_status> 0 </trans_status>
<Directory >&# 47; </directory>
<Parameters>
</Parameters>
<Log>
<Read/>
<Write/>
<Input/>
<Output/>
<Update/>
<Rejected/>
<Connection/>
<Table/>
<Step_performance_table/>
<Use_batchid> Y </use_batchid>
<Use_logfield> n </use_logfield>
</Log>
<Maxdate>
<Connection/>
<Table/>
<Field/>
<OFFSET> 0.0 </Offset>
<Maxdiff> 1, 0.0 </maxdiff>
</Maxdate>
<Size_rowset> 10000 </size_rowset>
<Sleep_time_empty> 50 </sleep_time_empty>
<Sleep_time_full> 50 </sleep_time_full>
<Unique_connections> n </unique_connections>
<Feedback_shown> Y </feedback_shown>
<Feedback_size> 50000 </feedback_size>
<Using_thread_priorities> Y </using_thread_priorities>
<Shared_objects_file/>
<Capture_step_performance> n </capture_step_performance>
<Step_performance_capturing_delay> 1000 </step_performance_capturing_delay>
<Dependencies>
</Dependencies>
<Partitionschemas>
</Partitionschemas>
<Slaveservers>
</Slaveservers>
<Clusterschemas>
</Clusterschemas>
<Modified_user>-</modified_user>
<Modified_date> 2008 & #47; 04 & #47; 29 14:56:48. 203 </modified_date>
</INFO>
<Notepads>
</Notepads>
<Order>
<Hop> <from> Get system setting date </from> <to> set variable </to> <enabled> Y </enabled> <Step>
<Name> getdatabasexml </Name>
<Type> getxmldata </type>
<Description/>
<Distribute> Y </distribute>
<Copies> 1 </Copies>
<Partitioning>
<Method> none </method>
<Schema_name/>
</Partitioning>
<Include> n </include>
<Shortde_field/>
<Rownum> n </rownum>
<Addresultfile> n </addresultfile>
<Namespaceaware> n </namespaceaware>
<Ignorecomments> n </ignorecomments>
<Readurl> n </readurl>
<Validating> n </validating>
<Usetoken> n </usetoken>
<Isignoreemptyfile> n </isignoreemptyfile>
<Donotfailifnofile> Y </donotfailifnofile>
<Rownum_field/>
<Encoding> UTF-8 </encoding>
<File>
<Name >$ {internal. transformation. filename. Directory} & #47; database. xml </Name>
<Filemask/>
<File_required> n </file_required>
</File>
<Fields>
<Field>
<Name> URL </Name>
<XPath> URL </XPath>
<Element_type> node </element_type>
<Type> string </type>
<Format/>
<Currency/>
<Decimal/>
<Group/>
<Length>-1 </length>
<Precision>-1 </precision>
<Trim_type> none </trim_type>
<Repeat> n </repeat>
</Field>
<Field>
<Name> classname </Name>
<XPath> classname </XPath>
<Element_type> node </element_type>
<Type> string </type>
<Format/>
<Currency/>
<Decimal/>
<Group/>
<Length>-1 </length>
<Precision>-1 </precision>
<Trim_type> none </trim_type>
<Repeat> n </repeat>
</Field>
<Field>
<Name> username </Name>
<XPath> username </XPath>
<Element_type> node </element_type>
<Type> string </type>
<Format/>
<Currency/>
<Decimal/>
<Group/>
<Length>-1 </length>
<Precision>-1 </precision>
<Trim_type> none </trim_type>
<Repeat> n </repeat>
</Field>
<Field>
<Name> password </Name>
<XPath> password </XPath>
<Element_type> node </element_type>
<Type> string </type>
<Format/>
<Currency/>
<Decimal/>
<Group/>
<Length>-1 </length>
<Precision>-1 </precision>
<Trim_type> none </trim_type>
<Repeat> n </repeat>
</Field>
</Fields>
<Limit> 0 </limit>
<Loopxpath> & #47; database </loopxpath>
<Isinfields> n </isinfields>
<Isafile> n </isafile>
<Xmlfield/>
<Prunepath/>
<Cluster_schema/>
<Remotesteps> <input> </input> <output> </remotesteps> <GUI>
<Xloc> 80 </xloc>
<Yloc> 71 </yloc>
<Draw> Y </draw>
</GUI>
</Step>
<Step>
<Name> obtain the system preset date </Name>
<Type> systeminfo </type>
<Description/>
<Distribute> Y </distribute>
<Copies> 1 </Copies>
<Partitioning>
<Method> none </method>
<Schema_name/>
</Partitioning>
<Fields>
<Field>
<Name> begintime </Name>
<Type> command line argument 1 </type>
</Field>
<Field>
<Name> yesterday </Name>
<Type> command line argument 2 </type>
</Field>
<Field>
<Name> today </Name>
<Type> command line argument 3 </type>
</Field>
</Fields>
<Cluster_schema/>
<Remotesteps> <input> </input> <output> </remotesteps> <GUI>
<Xloc> 276 </xloc>
<Yloc> 72 </yloc>
<Draw> Y </draw>
</GUI>
</Step>
<Step>
<Name> set variable </Name>
<Type> setvariable </type>
<Description/>
<Distribute> Y </distribute>
<Copies> 1 </Copies>
<Partitioning>
<Method> none </method>
<Schema_name/>
</Partitioning>
<Fields>
<Field>
<Field_name> URL </field_name>
<Variable_name> URL </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> classname </field_name>
<Variable_name> classname </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> username </field_name>
<Variable_name> username </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> password </field_name>
<Variable_name> password </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> begintime </field_name>
<Variable_name> begintime </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> yesterday </field_name>
<Variable_name> yesterday </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
<Field>
<Field_name> today </field_name>
<Variable_name> today </variable_name>
<Variable_type> root_job </variable_type>
<Default_value/>
</Field>
</Fields>
<Cluster_schema/>
<Remotesteps> <input> </input> <output> </remotesteps> <GUI>
<Xloc> 463 </xloc>
<Yloc> 68 </yloc>
<Draw> Y </draw>
</GUI>
</Step>
<Step_error_handling>
</Step_error_handling>
<Slave-step-copy-partition-distribution>
</Slave-step-copy-partition-distribution>
<Slave_transformation> n </slave_transformation>
</Transformation>
To use such a database connection, You must select generic database when writing a Ktr that requires database connection, as shown in:
In this way, we can first execute setvariable. Ktr when doing a job, and then execute Ktr to connect data.
However, I found in the test that not all Ktr can be used. Some can, but some cannot. What is the specific reason? I have not found it yet!
Further tests are required !!!