Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

This should make it easier:

http://ostermiller.org/utils/CSV.html
Some dbs can load CSV automatically btw
Avatar of chaitu chaitu

ASKER

through java i have to do this
I'd use the above with a PreparedStatement in batch mode
just tell me a psecudo code how to read csv file using CSVParser
You don't need pseudo. There's actual code on the main page:

http://ostermiller.org/utils/CSV.html
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("-----");
        }
>>how will u pass cvs file??

You don't pass the CVS file. You insert individual values in that array into the DB
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.......
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(If 'id' is not a String, obviously make the appropriate adjustments)
so what i am doing is correct

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