Customer Portal

charset error when inserting xls data into MySql

Comments 5

  • Avatar
    avackova
    0
    Comment actions Permalink
    Hello,
    Clover uses ISO-8859-1 charset by default . On XlsDataWriter or on DBOutput table you can set charset directly, but MySqlDataWriter can only work with default charset. You can change it in defaultProperties file, which should be located in CLOVER_HOME/lib/lib/cloveretl.engine.jar/org/jetel/data directory.
  • Avatar
    tchoua_12
    0
    Comment actions Permalink
    I tried your changes but I am unable to build a new jar file (I did it with gnome graphical arch tool but it didn't give me nothing good).

    I think it is more a date matter.
    I changed the FMT file from date to string and did the same on the MySql table.
    The insert run correctly on this field but drop in error (err) on the next date of the xls file.

    This test let me think that is not a charset problem on MySql but more a date format passed between clover and MySql that is not the proper date format for MySql.

    Do you know how can I see the date format passed to MySql ?

    Thanks

    Regards

    Francois
  • Avatar
    mhaupt
    0
    Comment actions Permalink
    Hello,
    Date column must be passed to MysqlDataWriter in proper date format for MySql.

    You can specify date values using any of a common set of formats:
    As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A “relaxed” syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent.
    As a string with no delimiters in either 'YYYYMMDD' or 'YYMMDD' format, provided that the string makes sense as a date. For example, '19970523' and '970523' are interpreted as '1997-05-23', but '971332' is illegal (it has nonsensical month and day parts) and becomes '0000-00-00'.
    As a number in either YYYYMMDD or YYMMDD format, provided that the number makes sense as a date. For example, 19830905 and 830905 are interpreted as '1983-09-05'.

    More info about date format: http://www.mysql.org/doc/refman/5.1/en/datetime.html
  • Avatar
    mhaupt
    0
    Comment actions Permalink
    Hello,
    there is a part of sample graph. It could help you with your problem.

    Xls file metadata. This format of date (dd-MM-yy) equals format of date in xls file (You change this format according to your format of date in xls file).
    <Metadata id="Metadata0">
    <Record name="fileMetadata" recordDelimiter="" recordSize="-1" type="delimited">
    <Field delimiter=";" format="dd-MM-yy" name="Field2" nullable="true" shift="0" type="date"/>
    </Record>
    </Metadata>


    MySql metadata. This format of date (yyyy-MM-dd) equals standard format of date for MySql.
    <Metadata id="Metadata1">
    <Record name="mysqlMetadata" recordDelimiter="" recordSize="-1" type="delimited">
    <Field delimiter=";" format="yyyy-MM-dd" name="Field2" nullable="true" shift="0" type="date"/>
    </Record>
    </Metadata>


    In addition to XLS Data Reader and MySql Writer you use Simple Copy component. It is used only for converting input format of date (xls file) to output format of date (MySql).
    <Edge fromNode="XLS_READER0:0" id="Edge0" inPort="Port 0 (in)" metadata="Metadata0" outPort="Port 0 (out)" toNode="SIMPLE_COPY0:0"/>
    <Edge fromNode="SIMPLE_COPY0:0" id="Edge1" inPort="Port 0 (in)" metadata="Metadata1" outPort="Port 0 (out)" toNode="MYSQL_DATA_WRITER0:0"/>


    This graph didn't tested. But I hope that it's ok.
  • Avatar
    tchoua_12
    0
    Comment actions Permalink
    Hello,

    Thanks a lot for your help. I used the solution proposed by mhaupt (thanks again) and now it is working fine.

    If some one has the same problem here is an example of the graph that worked for me :

    In this solution I added a node id="BROADCAST" witch serves to convert the date format from dd/MM/yyyy to Mysql date format yyyy-MM-dd.

    <?xml version="1.0" encoding="UTF-8"?>
    <Graph created="Tue Oct 24 10:36:22 CEST 2006" description="In this example data are read from ORDERS.xls file, partitioned to 3 parts and each of thees parts are saved in orders.partitioned.xls file in different sheets. " guiVersion="1.7" licenseType="Unlicensed clover.GUI" modified="Mon Jun 25 12:09:41 CEST 2007" name="loadXlsMoulinetteTrs" revision="1.21">
    <Global>
    <Metadata fileURL="FilesFMT/moulinette.fmt" id="Metadata0"/>
    <Metadata fileURL="FilesFMT/moulinetteTrs.fmt" id="Metadata1"/>

    <Property fileURL="workspace.prm" id="GraphParameter0"/>
    </Global>
    <Phase number="0">

    <Node enabled="enabled" id="BROADCAST" type="SIMPLE_COPY"/>

    <Node enabled="enabled"
    fileURL="FilesDBF/moulinette.xls"
    id="XLS_READER1"
    dataPolicy="Lenient"
    metadataRow="1"
    startRow="2"
    sheetNumber="0"
    type="XLS_READER"/>

    <Node id="MYSQL_WRITER"
    type="MYSQL_DATA_WRITER"
    myload="myload"
    hostname="localhost"
    database="test"
    dbTable="table_name"
    username="USER"
    password="XXXXXXX"/>

    <Edge fromNode="XLS_READER1:0" id="Edge0" inPort="Port 0 (in)" metadata="Metadata0" outPort="Port 0 (out)" toNode="BROADCAST:0"/>
    <Edge fromNode="BROADCAST:0" id="Edge1" inPort="Port 0 (in)" metadata="Metadata1" outPort="Port 0 (out)" toNode="MYSQL_WRITER:0"/>

    </Phase>
    </Graph>


    and here are the metadata file :

    the moulinette.fmt file (this file reads the XLS file) :
    <?xml version="1.0" encoding="UTF-8"?>
    <Record name="moulinette" type="delimited" charset="UTF-8">
    <Field delimiter="|" name="NAME" nullable="true" type="string"/>
    <Field delimiter="|" name="BIRTH_DATE" nullable="true" type="date" format="dd/MM/yyyy"/>
    </Record>


    the moulinetteTrs.fmt file (this file is used to convert date into MySql date format) :
    <?xml version="1.0" encoding="UTF-8"?>
    <Record name="moulinetteTrs" type="delimited" charset="UTF-8">
    <Field delimiter=";" name="NAME" nullable="true" type="string"/>
    <Field delimiter=";" name="BIRTH_DATE" nullable="true" type="date" format="yyyy-MM-dd"/>


    Hope it will be useful to somebody.

    Regards,

    Francois

Please sign in to leave a comment.