HSQLDB:dd / mm / yyyy的“无效日期时间格式”,但不适用于yyyy-mm-dd

时间:2016-10-02 12:46:43

标签: sql jdbc hsqldb

我的创建表

CREATE TABLE inventory (
  id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 100, INCREMENT BY 1) PRIMARY KEY,
  name VARCHAR(30),
  department  VARCHAR(50),
  inventory_type VARCHAR(255),
  expiry_date date NOT NULL
);

这是插入语句

INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('om', 'Education','Raw', '01/01/2016');
INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('hari', 'HR','Solid' ,'02/02/2016');
INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('hariom', 'Finance','Other', '03/03/2016');

但我得到了

  

引起:java.sql.SQLDataException:数据异常:datetime无效   org.hsqldb.jdbc.JDBCUtil.sqlException格式(未知来源)   〜[hsqldb-2.3.2.jar:2.3.2] at   org.hsqldb.jdbc.JDBCUtil.sqlException(未知来源)   〜[hsqldb-2.3.2.jar:2.3.2] at   org.hsqldb.jdbc.JDBCStatement.fetchResult(未知来源)   〜[hsqldb-2.3.2.jar:2.3.2] at   org.hsqldb.jdbc.JDBCStatement.execute(未知来源)   〜[hsqldb-2.3.2.jar:2.3.2] at   org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:457)   〜[spring-jdbc-4.1.6.RELEASE.jar:4.1.6.RELEASE] ... 60个常见帧   省略

有人可以告诉我出了什么问题吗?

但是当我改变下面的陈述时,它的工作正常

INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('om', 'Education','Raw', '2016-01-01');
INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('hari', 'HR','Solid' ,'2016-02-02');
INSERT INTO inventory (name, department,inventory_type,expiry_date) VALUES ('hariom', 'Finance','Other', '2016-03-03');

1 个答案:

答案 0 :(得分:3)

  

有人可以告诉我出了什么问题吗?

答案很简单,HSQLDB只接受日期的字符串文字,如果它们遵循'yyyy-mm-dd'格式。它愿意提供帮助 - 在某种程度上 - 它将允许我们从“适当的”HSQLDB日期文字值中省略DATE关键字

DATE '2016-01-02'

让我们简单地提供

'2016-01-02'

但它不会接受'01/02/2016'(无论如何都是模棱两可的)或any of the many other ways that we silly humans can represent dates