I am inserting data from a .csv file to my MySQl database table in eclipse using "load data local infile". However, I am getting the error message shown below.
Exception in thread "main" com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '1894' for column 'startYear' at row 1
Sample Data: tconst_titles,titleType,primaryTitle,originalTitle,isAdult,startYear,endYear,runtimeMinutes
tt1,short,Carmencita,Carmencita,0,1894,0000,1
tt2,short,Le clown et ses chiens,chiens,0,1892,0000,5
A similar thread mentioned that it has to do with the date values not being in the correct format. However, I have declared "startYear" as a date when creating the table and it should recognize '1894' as a year shouldn't it ?
Code for creating the table:
String sql1 = "CREATE TABLE Titles" +
"(tconst_titles VARCHAR(255) PRIMARY KEY, " +
" titleType VARCHAR(255), " +
" primaryTitle VARCHAR(255), " +
" originalTitle VARCHAR(255), " +
" isAdult TINYINT(1), " +
" startYear DATE, " +
" endYear DATE, " +
" runtimeMinutes INT)";
Code for inserting data from .csv file:
import java.sql.*;
public class populate {
public static void main(String[] args) throws SQLException {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/IMDB","root","user");
Statement stmt = con.createStatement();
String sql =
"load data local infile 'titles.csv' \n" +
" replace \n" +
" into table Titles \n" +
" columns terminated by '\\t' \n" +
" ignore 1 lines";
stmt.execute(sql);
}
}