t***@gmail.com
2013-03-21 08:26:47 UTC
I am using a java program to read lines from csv and insert them into mysql database. Whenever i run my program i discovered i could not insert values into a date field insert mysql if the value comming from the file is null. However if i change the field to a varchar, it works fine. I want to maintain the field as a date field. Below is the snippet of my code.
queryString = "INSERT INTO account (MNE,DATE1,DATE2,LINK) values('"+data[0]+"','"+data[1]+"','"+data[2]+"','"+data[3]+"')";
stmt=conn.createStatement();
val = stmt.executeUpdate(queryString);
and below is the line to be written
TEE,29-11-12,,90681
BBB,29-11-12,,90681
CCC,29-11-12,,90681
below is the error message (i think it comes because the value for DATE2 is null).
712 [pool-1-thread-1] ERROR main.ProcessInboxFileTask - Failed to upload: C:\Users\Teejay\Documents\NetBeansProjects\NetBeans 6.9.1\TEEJAYD\all\GTUS.csv
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '' for column 'DATE2' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3591)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
queryString = "INSERT INTO account (MNE,DATE1,DATE2,LINK) values('"+data[0]+"','"+data[1]+"','"+data[2]+"','"+data[3]+"')";
stmt=conn.createStatement();
val = stmt.executeUpdate(queryString);
and below is the line to be written
TEE,29-11-12,,90681
BBB,29-11-12,,90681
CCC,29-11-12,,90681
below is the error message (i think it comes because the value for DATE2 is null).
712 [pool-1-thread-1] ERROR main.ProcessInboxFileTask - Failed to upload: C:\Users\Teejay\Documents\NetBeansProjects\NetBeans 6.9.1\TEEJAYD\all\GTUS.csv
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: '' for column 'DATE2' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3591)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)