load data query is not working with INSERT/REPLACE option











up vote
0
down vote

favorite












I am trying to upload data from CSV file into a mysql database table but i am getting error "java.sql.SQLException: Invalid utf8 character string: '' " when using INSERT/REPLACE option in load data query. but the same query works fine without INSERT/REPLACE option.



Query:



Statement  stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String query = "LOAD DATA INFILE 'D:\"+flnm+"' REPLACE INTO TABLE prfl_hntr "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


I have verified the syntax in mysql documentation- https://dev.mysql.com/doc/refman/8.0/en/load-data.html.



Please note that i need to use REPLACE/IGNORE option in the query to eliminate duplicate entries.










share|improve this question
























  • LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
    – sk hussain
    Nov 21 at 11:26










  • and also check csv file permissions.
    – sk hussain
    Nov 21 at 11:28






  • 1




    Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
    – sk hussain
    Nov 21 at 11:33










  • Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
    – pmgowda
    Nov 21 at 11:49















up vote
0
down vote

favorite












I am trying to upload data from CSV file into a mysql database table but i am getting error "java.sql.SQLException: Invalid utf8 character string: '' " when using INSERT/REPLACE option in load data query. but the same query works fine without INSERT/REPLACE option.



Query:



Statement  stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String query = "LOAD DATA INFILE 'D:\"+flnm+"' REPLACE INTO TABLE prfl_hntr "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


I have verified the syntax in mysql documentation- https://dev.mysql.com/doc/refman/8.0/en/load-data.html.



Please note that i need to use REPLACE/IGNORE option in the query to eliminate duplicate entries.










share|improve this question
























  • LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
    – sk hussain
    Nov 21 at 11:26










  • and also check csv file permissions.
    – sk hussain
    Nov 21 at 11:28






  • 1




    Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
    – sk hussain
    Nov 21 at 11:33










  • Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
    – pmgowda
    Nov 21 at 11:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to upload data from CSV file into a mysql database table but i am getting error "java.sql.SQLException: Invalid utf8 character string: '' " when using INSERT/REPLACE option in load data query. but the same query works fine without INSERT/REPLACE option.



Query:



Statement  stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String query = "LOAD DATA INFILE 'D:\"+flnm+"' REPLACE INTO TABLE prfl_hntr "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


I have verified the syntax in mysql documentation- https://dev.mysql.com/doc/refman/8.0/en/load-data.html.



Please note that i need to use REPLACE/IGNORE option in the query to eliminate duplicate entries.










share|improve this question















I am trying to upload data from CSV file into a mysql database table but i am getting error "java.sql.SQLException: Invalid utf8 character string: '' " when using INSERT/REPLACE option in load data query. but the same query works fine without INSERT/REPLACE option.



Query:



Statement  stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

String query = "LOAD DATA INFILE 'D:\"+flnm+"' REPLACE INTO TABLE prfl_hntr "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


I have verified the syntax in mysql documentation- https://dev.mysql.com/doc/refman/8.0/en/load-data.html.



Please note that i need to use REPLACE/IGNORE option in the query to eliminate duplicate entries.







java mysql load-data-infile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked Nov 21 at 11:17









pmgowda

135




135












  • LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
    – sk hussain
    Nov 21 at 11:26










  • and also check csv file permissions.
    – sk hussain
    Nov 21 at 11:28






  • 1




    Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
    – sk hussain
    Nov 21 at 11:33










  • Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
    – pmgowda
    Nov 21 at 11:49


















  • LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
    – sk hussain
    Nov 21 at 11:26










  • and also check csv file permissions.
    – sk hussain
    Nov 21 at 11:28






  • 1




    Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
    – sk hussain
    Nov 21 at 11:33










  • Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
    – pmgowda
    Nov 21 at 11:49
















LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
– sk hussain
Nov 21 at 11:26




LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;
– sk hussain
Nov 21 at 11:26












and also check csv file permissions.
– sk hussain
Nov 21 at 11:28




and also check csv file permissions.
– sk hussain
Nov 21 at 11:28




1




1




Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
– sk hussain
Nov 21 at 11:33




Possible duplicate of Using "LOAD DATA LOCAL INFILE" in Java
– sk hussain
Nov 21 at 11:33












Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
– pmgowda
Nov 21 at 11:49




Hi hussain there was a typo in question. The problem is occuring when i am issuing command with REPLACE option. The query works fine without REPLACE option as suggested in the post in the link.
– pmgowda
Nov 21 at 11:49












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










You are right the issue is not with the syntax. The issue might be with difference in the characterset between Mysql table and your CSV file. I had a similar problem and resolved it by mentioning the characterset in the query. Try the query given below it should work and make sure your CSV file has data supported by Mysql table.



Query:



String  query = "LOAD DATA  INFILE 'D:\"+flnm+"'  REPLACE INTO TABLE prfl_hntr " 
+"character set latin1 "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


Further you can follow the answer by @RolandoMySQLDBA for this question-: Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT
It worked wonders for me.






share|improve this answer





















  • That works thank you.
    – pmgowda
    16 hours ago


















up vote
0
down vote













LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;



try this once.






share|improve this answer





















  • Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
    – pmgowda
    Nov 21 at 11:52













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410959%2fload-data-query-is-not-working-with-insert-replace-option%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You are right the issue is not with the syntax. The issue might be with difference in the characterset between Mysql table and your CSV file. I had a similar problem and resolved it by mentioning the characterset in the query. Try the query given below it should work and make sure your CSV file has data supported by Mysql table.



Query:



String  query = "LOAD DATA  INFILE 'D:\"+flnm+"'  REPLACE INTO TABLE prfl_hntr " 
+"character set latin1 "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


Further you can follow the answer by @RolandoMySQLDBA for this question-: Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT
It worked wonders for me.






share|improve this answer





















  • That works thank you.
    – pmgowda
    16 hours ago















up vote
0
down vote



accepted










You are right the issue is not with the syntax. The issue might be with difference in the characterset between Mysql table and your CSV file. I had a similar problem and resolved it by mentioning the characterset in the query. Try the query given below it should work and make sure your CSV file has data supported by Mysql table.



Query:



String  query = "LOAD DATA  INFILE 'D:\"+flnm+"'  REPLACE INTO TABLE prfl_hntr " 
+"character set latin1 "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


Further you can follow the answer by @RolandoMySQLDBA for this question-: Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT
It worked wonders for me.






share|improve this answer





















  • That works thank you.
    – pmgowda
    16 hours ago













up vote
0
down vote



accepted







up vote
0
down vote



accepted






You are right the issue is not with the syntax. The issue might be with difference in the characterset between Mysql table and your CSV file. I had a similar problem and resolved it by mentioning the characterset in the query. Try the query given below it should work and make sure your CSV file has data supported by Mysql table.



Query:



String  query = "LOAD DATA  INFILE 'D:\"+flnm+"'  REPLACE INTO TABLE prfl_hntr " 
+"character set latin1 "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


Further you can follow the answer by @RolandoMySQLDBA for this question-: Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT
It worked wonders for me.






share|improve this answer












You are right the issue is not with the syntax. The issue might be with difference in the characterset between Mysql table and your CSV file. I had a similar problem and resolved it by mentioning the characterset in the query. Try the query given below it should work and make sure your CSV file has data supported by Mysql table.



Query:



String  query = "LOAD DATA  INFILE 'D:\"+flnm+"'  REPLACE INTO TABLE prfl_hntr " 
+"character set latin1 "
+ "FIELDS TERMINATED by ',' LINES TERMINATED BY 'n' IGNORE 1 LINES"
+ " (candidate, phone, mailid, skill, texp, rexp, pctc,np);";
stmt.executeUpdate(query);


Further you can follow the answer by @RolandoMySQLDBA for this question-: Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT
It worked wonders for me.







share|improve this answer












share|improve this answer



share|improve this answer










answered 18 hours ago









pradyu

667




667












  • That works thank you.
    – pmgowda
    16 hours ago


















  • That works thank you.
    – pmgowda
    16 hours ago
















That works thank you.
– pmgowda
16 hours ago




That works thank you.
– pmgowda
16 hours ago












up vote
0
down vote













LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;



try this once.






share|improve this answer





















  • Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
    – pmgowda
    Nov 21 at 11:52

















up vote
0
down vote













LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;



try this once.






share|improve this answer





















  • Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
    – pmgowda
    Nov 21 at 11:52















up vote
0
down vote










up vote
0
down vote









LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;



try this once.






share|improve this answer












LOAD DATA LOCAL INFILE '/home/xxxxx/conf.csv' INTO TABLE configuration FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' IGNORE 1 ROWS;



try this once.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 11:27









sk hussain

8810




8810












  • Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
    – pmgowda
    Nov 21 at 11:52




















  • Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
    – pmgowda
    Nov 21 at 11:52


















Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
– pmgowda
Nov 21 at 11:52






Hi hussain, Please take into account that i need to use either IGNORE or REPLACE option because am trying to avoid duplicates when loading data. Also please note that this question is not a duplicate because this issue is not addressed in other post.
– pmgowda
Nov 21 at 11:52




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410959%2fload-data-query-is-not-working-with-insert-replace-option%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks