【问题标题】:Getting TypeDoesNotMatch on Timestamp field when inserting using Play Framework with Postgres使用 Play Framework 和 Postgres 插入时在时间戳字段上获取 TypeDoesNotMatch
【发布时间】:2014-10-21 09:47:08
【问题描述】:

我正在尝试将数据插入到名为 users 的表中。 我只为 name 字段传递了一个值,然后会弹出这个异常。

我什至没有在参数中传递任何时间戳。

即使发生这种情况,数据仍会插入到数据库中。为什么呢?

这是我得到的错误:[RuntimeException: TypeDoesNotMatch(Cannot convert 2014-10-21 17:41:41.982: class java.sql.Timestamp to Long for column ColumnName(users.joined,Some (加入)))]

代码如下:

DB.withConnection { implicit conn =>
  val id: Option[Long] =
    SQL("insert into pinglet.users (name) VALUES ('jel124')")
      .executeInsert()
    outString += id.getOrElse("nuffin'")
}

信息

joined 是带时区的时间戳数据类型字段。

我的 scala 版本是 2.11.1

java版本是1.8.0_25

我的 postgres jdbc 驱动是 9.3-1102-jdbc41

【问题讨论】:

    标签: sql postgresql scala playframework anorm


    【解决方案1】:

    我猜INSERT返回的pk是时间戳,你要求解析为Option[Long

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      相关资源
      最近更新 更多