parsing a fixed-width flat file to sql fields

Discussion in 'Java' started by clintsy, Mar 5, 2004.

  1. clintsy

    clintsy Guest

    I need to parse a plain text file (1,000's of records) into an arraylist (or similar collection) that can be dumped into SQL fields. I know the field lengths but i don't know how to forward...
    clintsy, Mar 5, 2004
    #1
    1. Advertising

  2. clintsy:

    >I need to parse a plain text file (1,000's of records) into an arraylist (or similar collection) that can be dumped into SQL fields. I know the field lengths but i don't know how to forward...


    Do you mean copying the data into a database?

    Create a PreparedStatement stat with "insert into" in it. The exact
    syntax depends on the table structure.

    Then for each input line:
    - Split the input string into several strings using String.substring.
    - Call trim() on the strings to remove trailing whitespace.
    - Copy fields into the PreparedStatement object with the correct index
    and set method, e.g. stat.setString(index, value);
    - Call the executeUpdate method of stat.

    BTW: Please make your newsclient use no more than about 80 characters
    per line!

    Regards,
    Marco
    --
    Please reply in the newsgroup, not by email!
    Java programming tips: http://jiu.sourceforge.net/javatips.html
    Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
    Marco Schmidt, Mar 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roy Smith
    Replies:
    2
    Views:
    1,510
    Alan Moore
    May 3, 2004
  2. Replies:
    11
    Views:
    1,073
    Toby Inkster
    Jan 28, 2005
  3. johnp
    Replies:
    4
    Views:
    3,651
    Toby Inkster
    May 23, 2005
  4. Nick da G

    Parsing Fixed Width File

    Nick da G, Apr 14, 2009, in forum: Ruby
    Replies:
    4
    Views:
    336
    Nick da G
    Apr 15, 2009
  5. Jim

    fixed width fields

    Jim, Sep 22, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    109
    Barry Kimelman
    Sep 24, 2003
Loading...

Share This Page