smv smv - 10 months ago 86
MySQL Question

unable to load from csv to mysql in java?

String query =LOAD DATA LOCAL INFILE 'airline.csv' INTO TABLE airline_tweets1 FIELDS TERMINATED BY '`' (tweet_id BIGINT,airline_sentiment VARCHAR,airline_sentiment_confidence DOUBLE,negativereason VARCHAR,negativereason_confidence VARCHAR,airline VARCHAR,airline_sentiment_gold VARCHAR,name VARCHAR,negativereason_gold VARCHAR,retweet_count INT,text VARCHAR,tweet_coord VARCHAR,tweet_created VARCHAR,tweet_location VARCHAR,user_timezone VARCHAR);

stmt.executeUpdate(query);


when i run the above query i get


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
'BIGINT,airline_sentiment VARCHAR,airline_sentiment_confidence
DOUBLE,negativerea' at line 1


How can i solve this?

Answer Source

You don't list the datatypes of the columns in the LOAD DATA query. They're just used when creating the table with a CREATE TABLE query.

   String query =LOAD DATA LOCAL INFILE 'airline.csv' INTO TABLE airline_tweets1  FIELDS TERMINATED BY '`' (tweet_id, airline_sentiment, airline_sentiment_confidence, negativereason, negativereason_confidence, airline , airline_sentiment_gold, name, negativereason_gold, retweet_count, text, tweet_coord, tweet_created, tweet_location, user_timezone);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download