-1

I want to know can I directly read and insert .csv file into my database or I need to read records one by one and insert them into my database.

5

2 Answers 2

1

you can try this query in your java program

LOAD DATA INFILE 'c:/tmp/filename.csv'
INTO TABLE tablename
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
Sign up to request clarification or add additional context in comments.

9 Comments

thanks Kishore, So could u plz guide me how to use this statement with JDBC
st = con.prepareStatement("LOAD DATA INFILE 'c:/tmp/filename.csv' INTO TABLE tablename FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';"); rs = st.executeQuery();
Thanks Kishore , will it load the whole csv file into my database, or it fetches row by row n then insert into my database.
One more thing , will it parse the data types implicitly while loading into database or it is programmer's responsibility to parse it into desired type.
with respect to programmer there is no need to parse all those are done implicitly in API and the whole csv file will be loaded
|
0
LOAD DATA INFILE 'file location'  -- File Name e.g /tmp/test.sql
INTO TABLE tablename
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS; -- If want to ignore header

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.