简体   繁体   English

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

[英]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.

相关问题 数据截断:错误的日期时间值 - Data truncation: Incorrect datetime value 数据截断:错误的日期时间值:“ - Data truncation: Incorrect datetime value: '' 数据截断:错误的日期时间值:“ - Data truncation: Incorrect datetime value: ' com.mysql.jdbc.MysqlDataTruncation:数据截断:错误的日期时间值:第1行“ INVOICE_DATE”列的“ Mon Feb 11 00:00:00 IST 2013” - com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: 'Mon Feb 11 00:00:00 IST 2013' for column 'INVOICE_DATE' at row 1 com.mysql.jdbc.MysqlDataTruncation:数据截断:错误的日期时间值:第1行的'lastchange'列的'0000-00-00 00:00:00' - com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '0000-00-00 00:00:00' for column 'lastchange' at row 1 Hibernate + Mysql:数据截断:日期时间值不正确 - Hibernate + Mysql : Data truncation: Incorrect datetime value 休眠-错误:数据截断:错误的日期时间值 - Hibernate - ERROR: Data truncation: Incorrect datetime value 数据截断:日期时间值不正确:Java中的“null” - Data truncation: Incorrect datetime value: 'null' in Java com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect date value: '2003' for column `mydb`.`cinema`.`Date_Diffusion` at row 1 - com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect date value: '2003' for column `mydb`.`cinema`.`Date_Diffusion` at row 1 数据截断:错误的日期时间值:org.joda.time.DateTime - Data truncation: Incorrect datetime value: org.joda.time.DateTime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM