reading a csv file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srujanaa
    New Member
    • Feb 2008
    • 1

    reading a csv file

    When we read a csv file using java and tokenize it using StringTokenizer ,and if we encounter a blank space how to save that empty space as null.
    Example: Supposing we have a string "abc,xyz, ,str,".
    When we read it, it is taking as a line including the space.But when we tokenize it the output is :
    abc
    xyz
    str

    But I want the output as:
    abc
    "empty space"
    xyz
    "emptyspace ", so that I can replace the empty space with null value while inserting into the database.

    Thanks in advance.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by srujanaa
    When we read a csv file using java and tokenize it using StringTokenizer ,and if we encounter a blank space how to save that empty space as null.
    Example: Supposing we have a string "abc,xyz, ,str,".
    When we read it, it is taking as a line including the space.But when we tokenize it the output is :
    abc
    xyz
    str

    But I want the output as:
    abc
    "empty space"
    xyz
    "emptyspace ", so that I can replace the empty space with null value while inserting into the database.

    Thanks in advance.
    1.) Replace that old StringTokenizer with String.split.
    2.) Just skip that column when inerting into the database, null will be inserted if the column allows nulls.

    Comment

    Working...