• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

upload the csv file those records should be inserted corresponding fields of the table in the dabatase

i have a csv file in that i have  id and name columns and the corresponding values below that.my requirement is i will upload that csv file those records should be inserted corresponding fields of the table in the dabatase.how will i do this?
0
chaitu chaitu
Asked:
chaitu chaitu
  • 9
  • 5
1 Solution
 
CEHJCommented:
This should make it easier:

http://ostermiller.org/utils/CSV.html
0
 
CEHJCommented:
Some dbs can load CSV automatically btw
0
 
chaitu chaituAuthor Commented:
through java i have to do this
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
I'd use the above with a PreparedStatement in batch mode
0
 
chaitu chaituAuthor Commented:
just tell me a psecudo code how to read csv file using CSVParser
0
 
CEHJCommented:
You don't need pseudo. There's actual code on the main page:

http://ostermiller.org/utils/CSV.html
0
 
chaitu chaituAuthor Commented:
ur talking abt this;but here how will u pass cvs file??

String[][] values = CSVParser.parse(new StringReader(""));

// Display the parsed data
        for (int i=0; i<values.length; i++){
            for (int j=0; j<values[i].length; j++){
                System.out.println(values[i][j]);
            }
            System.out.println("-----");
        }
0
 
CEHJCommented:
>>how will u pass cvs file??

You don't pass the CVS file. You insert individual values in that array into the DB
0
 
chaitu chaituAuthor Commented:
String[][] values = CSVParser.parse(new FileReader(new File("c:/chaitu/emp.csv")));

// Display the parsed data
        for (int i=0; i<values.length; i++){
            for (int j=0; j<values[i].length; j++){
                System.out.println(values[i][j]);
            }
            System.out.println("-----");
        }

in the emp.csv file i have id and name values will be stored.......
0
 
CEHJCommented:
>>
          for (int j=0; j<values[i].length; j++){
                System.out.println(values[i][j]);
            }
>>

Replace the above by

ps.setString("id", values[i][0]);
ps.setString("name", values[i][1]);
ps.addBatch();
0
 
CEHJCommented:
(If 'id' is not a String, obviously make the appropriate adjustments)
0
 
chaitu chaituAuthor Commented:
so what i am doing is correct

String[][] values = CSVParser.parse(new FileReader(new File("c:/chaitu/emp.csv")));
0
 
CEHJCommented:
Yes
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now