繁体   English   中英

数据截断:错误的日期时间值:第1行的“日期”列为“

[英]Data truncation: Incorrect datetime value: '' for column 'date' at row 1

我的应用程序出现此错误:

数据截断:错误的日期时间值:第1行的“ POrder_Date”列为“ 2-24-2015”

我有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;

以下代码在我的类的构造函数中:

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默认日期格式为“ 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);
    }

检查打印日期格式如(2015-05-25)。

您有两种选择:

在当前使用rs.updateString(2,podate)地方使用updateDate() rs.updateString(2,podate) Date对象传递给updateDate()

或更改整个内部日期格式以符合ISO yyyy-mm-dd标准。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM