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?
LVL 20
chaitu chaituAsked:
Who is Participating?
 
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:
This should make it easier:

http://ostermiller.org/utils/CSV.html
0
 
CEHJCommented:
Some dbs can load CSV automatically btw
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
chaitu chaituAuthor Commented:
through java i have to do this
0
 
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:
(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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.