2

I am trying to read data from a text file and input them into a database. I found this example in the SQL docs that fits my case:

LOAD DATA INFILE 'data.txt' INTO TABLE table2 FIELDS TERMINATED BY ',';

So I am trying to write this in Java. So far I have this:

String insertTableSQL = "LOAD DATA INFILE 'C:/Users/Work/Desktop/test/masterDict'"
                    + "INTO TABLE masterdict" + "FIELDS TERMINATED BY \',\'" 
                    ;

But this gives me the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TERMINATED BY ','' at line 1

1 Answer 1

2

You miss some blanks:

String insertTableSQL = "LOAD DATA INFILE 'C:/Users/Work/Desktop/test/masterDict '"
                    + " INTO TABLE masterdict" + " FIELDS TERMINATED BY \',\'" 
                    ;

Because you querystring will result in:

LOAD DATA INFILE 'C:/Users/Work/Desktop/test/masterDict'INTO TABLE masterdictFIELDS TERMINATED BY \',\'
Sign up to request clarification or add additional context in comments.

4 Comments

Jens thank you for your answer :) it works i have no syntax errors now, but instead it gives me this "The MySQL server is running with the --secure-file-priv option so it cannot execute this statement" do you have any idea what this is?
Thank you! Should i edit my question to include this link too? I think a lot of beginners might run to both problems as well.
I would upvote your answer as well but unfortunately i must have at least 15 reputation

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.