使用apache scriptella

时间:2017-08-07 13:42:52

标签: scriptella

我想使用scriptella将数据从oracle复制到postgresql数据库。但是我有一个列tel,在两个数据库中有不同的类型,一个是varchar,另一个是大int,我怎么能转换这里隐含的是etl文件。

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
    <description>
        test script
    </description>
    <connection id="in" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:XE"
        user="test" password="test">

    </connection>

    <connection id="out" driver="postgresql"
        url="jdbc:postgresql://localhost:5432/testMonoprix2" user="postgres"
        password="maher">
    </connection>
    <query connection-id="in">
        SELECT LIBELLE, ADRESSE,MATFISC,CONTACT,TEL FROM IPTECH.TMP_FOURNISSEUR;
        <script connection-id="out">
            UPDATE public.suppliers  SET is_enabled='TRUE', label=?LIBELLE, address=?ADRESSE, tax_registration_number=?MATFISC,contact=?CONTACT, tel=?TEL;
            </script>

    </query>
</etl>

这是java代码

这是我得到的错误

import java.io.File;
import scriptella.execution.EtlExecutor;
import scriptella.execution.EtlExecutorException;
public final class Test_Scriptella 
public static void main(String[] args) throws EtlExecutorException {
        try {
                    EtlExecutor.newExecutor(new File("oracle_etl.xml")).execute();
                      System.out.println("file executed");

                }catch(Exception ex)
                {
                    System.out.println(ex.getMessage());
                }
        }
    }

这是我得到的错误

 Location: /etl/query[1]/script[1]
    JDBC provider exception: Unable to execute statement
    Error statement: 
    UPDATE public.suppliers SET is_enabled='TRUE', label=?, address=?, tax_registration_number=?,contact=?, tel=?. Parameters: [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, MONOPRIX LAFAYETTE, null, Neant, 891 656 ]
    Error codes: [42804, 0]
    Driver exception: org.postgresql.util.PSQLException: ERREUR: la colonne « tel » est de type bigint mais l'expression est de type character varying
     Hint: Vous devez réécrire l'expression ou lui appliquer une transformation de type.
     Position: 114

1 个答案:

答案 0 :(得分:0)

我没试过,但一个选项是使用cast()函数转换为int:

UPDATE public.suppliers  SET is_enabled='TRUE', label=?LIBELLE, address=?ADRESSE, tax_registration_number=?MATFISC,contact=?CONTACT, tel=cast(?TEL as bigint);