java - 在 mysql 服务器 Play Framework 中存储日期时间

标签 java mysql datetime playframework-2.0

我有一个连接到 mysql 服务器的 Play 应用程序,在模型中我有一些属性,我想将它们保存为 DateTimes,但是使用 java.sql.Timestamp 会在我的演化中生成用于创建表的属性

 create table delivery (
  id                        bigint auto_increment not null,
  deleted                   tinyint(1) default 0,
  description               varchar(500),
  notes                     varchar(1000),
  account_id                bigint,
  customer_id               bigint,
  sender_id                 bigint,
  recipient_id              bigint,
  delivery_status_id        bigint,
  delivery_type_id          bigint,
  package_type_id           bigint,
  item_type_id              bigint,
  call_date                 datetime(6),
  pickup_date               datetime(6),
  delivery_date             datetime(6),
  no_of_pieces              integer,
  cust_type                 integer,
  payment_type              integer,
  way_bill                  integer,
  created_time              date,
  modified_time             date,
  createdby_id              bigint,
  modifiedby_id             bigint,
  constraint pk_delivery primary key (id))

这又会导致 mysql 错误:

We got the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6), modified_time datetime(6), createdby_id bigint, mo' at line 21 [ERROR:1064, SQLSTATE:42000], while trying to run this SQL script:

我了解到是大小参数 (6) 导致了问题,并且能够通过使用 java.sql.Date 来避免它(因为它不会在演化中产生)是否有其他人经历过这种情况并知道一种方法在这些条件下存储日期时间?

最佳答案

我能够通过使用 @Column 注释来定义 sql 中的类型来解决这个问题。

    @Column(columnDefinition = "datetime")
    public Timestamp createdAt;

关于java - 在 mysql 服务器 Play Framework 中存储日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196852/

相关文章:

c# - 在 C# WinForm 中计算# of Years Alive

php - 可选的日期、时间、为Mysql数据库归档的日期时间

java - 如何将 txt 文件中的数据提取到 HTML 表 Java/JSP

java - 从打开的 Office 文件中获取元数据

java - 在控制台上正确对齐字符串

mysql - JMeter无法连接本地数据库

mysql - 如何在 Visual Web Developer 2010 Express 中从数据库更新模型?

php - PHP OOP查询无法正确更新数据库

python - Pandas :合并时间范围条件

java - 如何保存位图并从缓存中共享?