Firefox logo

Ant logo

Netbeans logo

Quickstart guide

CsvToSql is a platform indipendent conversion tool, converts data from csv based or from xls (excel) file. All you need to do is to compile the descriptor xml file tipically called descriptor.xml, wich will contain all conversion options (like structure of data, where to save it, ...) and pass it to one the frontends (actually there are two frontends, console and graphics).

To run console frontend go to "bin" directory and execute run.bat or run.sh (windows or linux) , for the graphic frontend execute runGUI.bat or runGUI.sh (windows or linux).

Compiling descriptor.xml: (download example)

This file must be in same directory of input file.
If you don't want to write a descriptor from zero you can take one in example directory.
There are four sections:

1 - <structure>
define the name and the type of fields, optionally some conversion parameter (like date formats).
Is very simple to compile.

Example:
    <structure tablename="tab_users">
        <field name="name" type="String"/>
        <field name="surname" type="String"/>
        <field name="age" type="Integer"/>
        <field name="borndate" type="Date">
            <param name="inputformat" value="ddmmyy"/>
            <param name="outputformat" value="dd-mm-yy"/>
        </field>
    </structure>

2 - <grammar>
grammars define how data is formatted based on database. Csvtosql come with three grammars, default grammar is net.sf.csv2sql.grammars.standard.GrammarFactory based on sql/92 standard.
the others are net.sf.csv2sql.grammars.mysql.GrammarFactory based on mysql standard and net.sf.csv2sql.grammars.oracle.GrammarFactory based on oracle standard.

Example:
    <grammar class="net.sf.csv2sql.grammars.standard.GrammarFactory"/>

3 - <render>
renderers define how data is converted.
Actually csvtosql come with three renderers net.sf.csv2sql.renders.SqlInsertRenderer read data from csv and write sql statements and net.sf.csv2sql.renders.SqlInsertRendererFromExcel, the same but read data from excel.

Example:
    <render class="net.sf.csv2sql.renders.SqlInsertRenderer">
        <param name="inputfile" value="users.txt"/>
        <param name="separator" value=","/>
    </render>

4 - <output>
This section define how and where write results, you can use more than one writer. You can enable or disable writer setting true or false active flag

Example:
    <writerAppender active="true"
        class="net.sf.csv2sql.writers.SqlFileWriter">
        <param name="filename" value="users.sql"/>
    </writerAppender>

other writers are:
net.sf.csv2sql.writers.SqlFileWriter write statements to file net.sf.csv2sql.writers.StandardOutputWriter write statemens to standard output, net.sf.csv2sql.writers.JDBCBatchWriter load csv data to jdbc resource in batch mode and net.sf.csv2sql.writers.JDBCWriter load csv data directly in a jdbc resource.

copyright 2004 Davide Consonni (davideconsonni@users.sourceforge.net)