有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java向Derby数据库中插入日期值的问题

我正在尝试建立一个Derby数据库,并将一些样本信息插入其中进行测试

获取我想要的表格的代码是

CREATE TABLE users(
    userid varchar(128) primary key, 
    passwd_digest varchar(128)
    );
CREATE TABLE customers(
    cust_id int not null primary key(START WITH 1, INCREMENT BY 1), 
    cust_name varchar(128)
    );
CREATE TABLE orders(
    order_id int not null primary key, 
    cust_id int not null(START WITH 1, INCREMENT BY 1),
    foreign key(cust_id) references customers(cust_id), 
    order_date date, 
    order_desc varchar(128)
    );

现在,当我尝试使用以下代码将示例数据插入其中时:

insert into customers(cust_id, cust_name) values (3, 'Ringo');
insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, 12.12.1957, 'A drumset');

我从IJ得到以下错误:

ERROR 42X01: Syntax error: Encountered ".1957" at line 1, column 82.
Issue the 'help' command for general information on IJ command syntax.
Any unrecognized commands are treated as potential SQL commands and executed directly.
Consult your DBMS server reference documentation for details of the SQL syntax supported by your server.

我试着用以下方式输入日期值(忽略其他数据,只有日期似乎不起作用):

insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, 1957-12-12 00:00:00:000, 'A drumset');
insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, 1957-12-12, 'A drumset');
insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, "12-12-1957", 'A drumset');
insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, DATE("12-12-1957"), 'A drumset');
insert into orders(order_id, cust_id, order_date, order_desc) values (4, 3, 12-12-1957, 'A drumset');

但它们都会产生类似的错误,包括:

ERROR 42821: Columns of type 'DATE' cannot hold values of type 'INTEGER'. 

我不确定为什么会出现这些错误,因为我输入了与Derby文档格式相匹配的值(至少在我看来是这样的,因为它不起作用,我确定我在某个地方搞错了)


共 (0) 个答案