简体   繁体   English

数据截断:错误的日期时间值

[英]Data truncation: Incorrect datetime value

I work in a spring project which uses mysql db. 我在使用mysql db的spring项目中工作。 When every insert and update sql command runs in backend side of the project while the app is running in my local, i got these type exceptions for "datetime" variables; 当每个应用程序在本地运行时,每个插入和更新sql命令都在项目的后端运行时,我收到了“ datetime”变量的这些类型异常;

Caused by: java.sql.BatchUpdateException: Data truncation: Incorrect datetime value: '' for column 'CREATION_DATE' at row 1 at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 54 more 由以下原因引起:java.sql.BatchUpdateException:数据截断:错误的日期时间值:org.hibernate.jdbc上com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)第1行的“ CREATION_DATE”列为“”。 org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)的BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)... 54更多

Mysql version: 5.7.18, mysql-connector-java version: -5.1.38, user-timezone is"-Duser.timezone=Europe/Istanbul" in tomcat 7 vm arguments and db timezone: GMT +3 Mysql版本:5.7.18,mysql-connector-java版本:-5.1.38,用户时区在tomcat 7 vm参数和db时区中为“ -Duser.timezone = Europe / Istanbul”:GMT +3

Sample code block; 示例代码块;

        ResponseCreateTicket response = new ResponseCreateTicket();
        TicketDTO ticket=new TicketDTO();
ticket.setTicketNumber(UUID.randomUUID().toString().toUpperCase(Locale.ENGLISH));
        ticket.setStatus(TicketStatus.UNCOMPLETED.toString());
        Date date = new Date();
        ticket.setCreatedOn(date);
        ticket.setReferenceNumber(request.getReferenceNumber());
        getTicketDAO().createTicket(ticket);
        response.setTicketNumber(ticket.getTicketNumber());
        return response;

The sql hibernate showed and binded parameters; sql hibernate显示并绑定了参数;

Hibernate: insert into eis_ticket (TICKET_NUMBER, STATUS, CREATED_BY, CREATION_DATE, LAST_UPDATED_BY, LAST_UPDATE_DATE, REFERENCE_NUMBER, ID) values (?, ?, ?, ?, ?, ?, ?, ?) 2018-05-16 10:57:37 TRACE BasicBinder:? 休眠状态:插入eis_ticket(TICKET_NUMBER,STATUS,CREATED_BY,CREATION_DATE,LAST_UPDATED_BY,LAST_UPDATE_DATE,REFERENCE_NUMBER,ID)值(?,?,?,?,?,?,?,?,?)2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [1] as [VARCHAR] - 9BF25A08-C442-45FA-A95F-8E59502CE037 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[1]绑定为[VARCHAR]-9BF25A08-C442-45FA-A95F-8E59502CE037 2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [2] as [VARCHAR] - UNCOMPLETED 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[2]绑定为[VARCHAR]-未完成2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [3] as [VARCHAR] - 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[3]绑定为[VARCHAR] -2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [4] as [TIMESTAMP] - Wed May 16 10:57:32 EEST 2018 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[4]绑定为[TIMESTAMP]-2018年5月16日星期三10:57:32 EEST 2018年5月16日 10:57:37 TRACE BasicBinder :? - binding parameter [5] as [VARCHAR] - 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[5]绑定为[VARCHAR]-2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [6] as [TIMESTAMP] - 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[6]绑定为[TIMESTAMP]-2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [7] as [VARCHAR] - b4be9b87-21c4-4001-b80d-244420ab2e00 2018-05-16 10:57:37 TRACE BasicBinder:? -将参数[7]绑定为[VARCHAR]-b4be9b87-21c4-4001-b80d-244420ab2e00 2018-05-16 10:57:37 TRACE BasicBinder :? - binding parameter [8] as [BIGINT] - 1925 2018-05-16 10:57:37 ERROR JDBCExceptionReporter:? -将参数[8]绑定为[BIGINT]-1925 2018-05-16 10:57:37错误JDBCExceptionReporter :? - Data truncation: Incorrect datetime value: '' for column 'CREATION_DATE' at row 1 -数据截断:日期时间值不正确:第1行的“ CREATION_DATE”列

The date format can be change to "yyyy-MM-dd HH:mm:ss" but there is hundreds of these types codes in project so it will not be the right solution. 日期格式可以更改为“ yyyy-MM-dd HH:mm:ss”,但是项目中有数百种此类类型代码,因此它不是正确的解决方案。 What could be causing this problem? 是什么导致此问题? Mysql connector is updated but not worked. Mysql连接器已更新,但不起作用。

If the column type is date-time, you can easily modify the column and set the default to CURRENT_TIMESTAMP , this will ensure that every record inserted will default to the current server date and time. 如果列类型是日期时间,则可以轻松地修改列并将默认值设置为CURRENT_TIMESTAMP ,这将确保插入的每个记录都将默认为当前服务器的日期和时间。 However if you are generating the timestamp manually, then the data type generated on the app, is not similar to the data type used when inserting in the database You can use this to modify the column default, then leave the creation_type column NULL when inserting a record. 但是,如果您是手动生成时间戳,则在应用程序上生成的数据类型将不同于在数据库中插入时使用的数据类型。您可以使用它来修改列的默认值,然后在插入数据库时​​将creation_type列保留为NULL 。记录。

ALTER TABLE table MODIFY CREATION_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL; ALTER TABLE table MODIFY CREATION_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

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

相关问题 数据截断:错误的日期时间值:“ - Data truncation: Incorrect datetime value: '' 数据截断:错误的日期时间值:“ - Data truncation: Incorrect datetime value: ' 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 数据截断:错误的日期时间值:org.joda.time.DateTime - Data truncation: Incorrect datetime value: org.joda.time.DateTime com.mysql.jdbc.MysqlDataTruncation:数据截断:不正确的日期时间值:'' - com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ' ' 数据截断:错误的日期时间值:第1行的“日期”列为“ - Data truncation: Incorrect datetime value: '' for column 'date' at row 1 为什么会出现“ com.mysql.jdbc.MysqlDataTruncation:数据截断:不正确的datetime值:”错误? - Why do I get a “com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value:” error? 数据截断:截断不正确的 DOUBLE 值:更新时 - Data truncation: Truncated incorrect DOUBLE value: on update
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM