【问题标题】:Cannot convert value '2017-01-26 11:47:54.000000' from column 14 to TIMESTAMP无法将值 '2017-01-26 11:47:54.000000' 从第 14 列转换为 TIMESTAMP
【发布时间】:2017-06-11 15:13:28
【问题描述】:

注意:这不是一个重复的问题。

我按照this教程将MSSQL数据库迁移到Mysql数据库。

有一个日期时间归档为date_in,在表格中为main。因此,当我使用 mysql 查询选择 date_in 时,它可以正常工作,如下所示

SELECT DATE_IN FROM incoming_audit.main where DATE_IN is not null limit 0, 50000;

在 Java - Spring-Hibernate 中,当我尝试从 main 表中获取前 25 条记录时,它给了我以下错误

错误(不允许我粘贴无效字符,见下图)

Hibernate: select this_.ID as ID1_1_0_, this_.AVAILABLE as AVAILABL2_1_0_, this_.BATTERY as BATTERY3_1_0_, this_.BOX as BOX4_1_0_, this_.CAPS as CAPS5_1_0_, this_.COA_EDITION as COA_EDIT6_1_0_, this_.COA_VERSION as COA_VERS7_1_0_, this_.CPU as CPU8_1_0_, this_.CPU_CORES as CPU_CORE9_1_0_, this_.CPU_DATA_WIDTH as CPU_DAT10_1_0_, this_.CPUSPD as CPUSPD11_1_0_, this_.CUSTOMER_ASSET as CUSTOME12_1_0_, this_.CUSTOMER_ID as CUSTOME13_1_0_, this_.DATE_IN as DATE_IN14_1_0_, this_.DATE_INC as DATE_IN15_1_0_, this_.FORM_FACTOR as FORM_FA16_1_0_, this_.HDD_INC_SERIAL as HDD_INC17_1_0_, this_.HDD_MODEL as HDD_MOD18_1_0_, this_.HDD_SERIAL as HDD_SER19_1_0_, this_.HDD_SIZE as HDD_SIZ20_1_0_, this_.HDD_SMART as HDD_SMA21_1_0_, this_.INC_TECH as INC_TEC22_1_0_, this_.INT_SERIAL as INT_SER23_1_0_, this_.KILLDISK as KILLDIS24_1_0_, this_.LOCATION as LOCATIO25_1_0_, this_.LOT_ID as LOT_ID26_1_0_, this_.MANUFACTURER as MANUFAC27_1_0_, this_.MODEL as MODEL28_1_0_, this_.NOTES as NOTES29_1_0_, this_.PALETTE as PALETTE30_1_0_, this_.PLASTIC_CONDITION as PLASTIC31_1_0_, this_.POWER_ADAPTER as POWER_A32_1_0_, this_.PXE_TECH as PXE_TEC33_1_0_, this_.RAM_PER_SLOT as RAM_PER34_1_0_, this_.RAM_SLOTS as RAM_SLO35_1_0_, this_.SCREEN_CONDITION as SCREEN_36_1_0_, this_.SERIAL as SERIAL37_1_0_, this_.TOTAL_RAM as TOTAL_R38_1_0_, this_.WEBCAM as WEBCAM39_1_0_ from Main this_ limit ?
2017-01-26 11:48:33 [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] WARN   - SQL Error: 0, SQLState: S1009
2017-01-26 11:48:33 [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] ERROR  - Cannot convert value '2017-01-26 11:47:54.000000' from column 14 to TIMESTAMP.
Jan 26, 2017 11:48:33 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/sts] threw exception [Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query] with root cause
java.lang.NumberFormatException: 81646
SOLDRETAILû

列映射

@Type(type = "timestamp")
@Column(name = "DATE_IN", nullable = true)
private Date dateIn;

如何去除无效字符?

更新

当我运行以下查询时,我的代码运行完美

UPDATE incoming_audit.main SET DATE_IN=null WHERE DATE_IN is not null;

但是当我在运行上面的查询之后运行下面的查询时,又会出现无效字符的异常

UPDATE incoming_audit.main SET DATE_IN=now() WHERE DATE_IN is null;

但这次是不同的例外。

【问题讨论】:

  • 您是否尝试将其粘贴到记事本中?或记事本++
  • 是的,我将它粘贴到notepad++,它粘贴在notepad++上,所有无效字符。
  • DATE_IN的数据类型是什么?
  • 删除无效字符,然后更新错误字段本身。
  • 我认为根据hibernate和JDBC驱动@​​987654338@不是timestamp;尝试检查您的数据库 date_in 数据类型也许您必须正确配置休眠

标签: java mysql sql-server spring hibernate


【解决方案1】:

我遇到了类似的问题,寻找选择的人,

Caused by: java.sql.SQLException: Cannot convert value '2021-04-23 10:43:54.000000' from column 15 to TIMESTAMP.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) ~[mysql-connector-java-5.1.7.jar:?]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) ~[mysql-connector-java-5.1.7.jar:?]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) ~[mysql-connector-java-5.1.7.jar:?]
    at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:1328) ~[mysql-connector-java-5.1.7.jar:?]
    at com.mysql.jdbc.BufferRow.getTimestampFast(BufferRow.java:573) ~[mysql-connector-java-5.1.7.jar:?]

此列的数据类型为 datetime(6)。数据是通过休眠添加的,当我尝试加载数据时出现此错误。

该列是相关的最后修改时间戳。

@Column(
        name = "last_modified_time",
        nullable = false
)
@Temporal(TemporalType.TIMESTAMP)
private Date lastModifiedTime;

由于timestamp 更适合这里,我使用了timestamp 数据类型而不是datetime(6),它无需任何其他修改即可解决问题。

【讨论】:

    猜你喜欢
    • 2018-02-23
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    相关资源
    最近更新 更多