[英]Data truncation: Incorrect datetime value: '' for column 'date' at row 1
My application is getting this error: 我的应用程序出现此错误:
Data truncation: Incorrect datetime value: '2-24-2015' for column 'POrder_Date' at row 1
数据截断:错误的日期时间值:第1行的“ POrder_Date”列为“ 2-24-2015”
I have MySQL connector java v-5.1.7 我有MySQL连接器Java v-5.1.7
java.util.Date date = new java.util.Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String date1, mon, datex, year, yearx, currentDate;
int d, d1;
following code is in my class,s constructor: 以下代码在我的类的构造函数中:
date1=df.format(date);
d=date1.indexOf('/');
mon=date1.substring(0,d);
d1=date1.lastIndexOf('/');
datex=date1.substring(d+1,d1);
yearx=date1.substring(d1+1);
year="20"+yearx;
currentDate=mon+"-"+datex+"-"+year;
System.out.println("current date "+currentDate);
mysql default date format "yyyy-mm-dd".change date format then store .may be it will work. mysql默认日期格式为“ yyyy-mm-dd”。更改日期格式然后存储。
java.util.Date date = new java.util.Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
String date1,mon,datex,year,yearx,currentDate;
int d,d1;
date1=df.format(date);
d=date1.indexOf('/');
mon=date1.substring(0,d);
d1=date1.lastIndexOf('/');
datex=date1.substring(d+1,d1);
yearx=date1.substring(d1+1);
year="20"+yearx;
currentDate=mon+"-"+datex+"-"+year;
System.out.println("current date "+currentDate);
//change currentdate format MM-dd-yyyy into yyyy-MM-dd
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
Date convertedCurrentDate = sdf.parse(currentDate);
System.out.println(new SimpleDateFormat("yyyy-MM- dd").format(convertedCurrentDate));
} catch (ParseException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
check print date format like(2015-05-25). 检查打印日期格式如(2015-05-25)。
You have two choices here: 您有两种选择:
Either use updateDate()
where you presently use rs.updateString(2,podate)
. 在当前使用
rs.updateString(2,podate)
地方使用updateDate()
rs.updateString(2,podate)
。 Pass a Date
object to updateDate()
. 将
Date
对象传递给updateDate()
。
Or change your internal date formatting throughout to comply with the ISO yyyy-mm-dd
standard. 或更改整个内部日期格式以符合ISO
yyyy-mm-dd
标准。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.