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

TRiG
  • 9,249
  • 6
  • 50
  • 101

1 Answers1

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 \',\'
Jens
  • 60,806
  • 15
  • 81
  • 95
  • 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? – Steve Emman Aug 01 '16 at 07:51
  • @SteveEmman Read here: http://stackoverflow.com/questions/32737478/mysql-how-to-tackle-secure-file-priv – Jens Aug 01 '16 at 07:53
  • 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. – Steve Emman Aug 01 '16 at 08:00
  • I would upvote your answer as well but unfortunately i must have at least 15 reputation – Steve Emman Aug 01 '16 at 08:04