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.
-
1Directly or using java? and how it's related to oracle?StanislavL– StanislavL2015-01-27 07:11:33 +00:00Commented Jan 27, 2015 at 7:11
-
dev.mysql.com/doc/refman/5.1/en/load-data.html or mysqltutorial.org/import-csv-file-mysql-tableStanislavL– StanislavL2015-01-27 07:13:11 +00:00Commented Jan 27, 2015 at 7:13
-
Look here maybe this helps.Jens– Jens2015-01-27 07:13:43 +00:00Commented Jan 27, 2015 at 7:13
-
possible duplicate of Using "LOAD DATA LOCAL INFILE" in JavaYazan– Yazan2015-01-27 07:17:31 +00:00Commented Jan 27, 2015 at 7:17
-
Using Java i need to read and insert .csv file into databaseAamir Shaikh– Aamir Shaikh2015-01-27 07:32:33 +00:00Commented Jan 27, 2015 at 7:32
Add a comment
|
2 Answers
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'
9 Comments
Aamir Shaikh
thanks Kishore, So could u plz guide me how to use this statement with JDBC
Kishore
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();
Aamir Shaikh
Thanks Kishore , will it load the whole csv file into my database, or it fetches row by row n then insert into my database.
Aamir Shaikh
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.
Kishore
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
|