我有以下
DateFormat dformat = new SimpleDateFormat("yyyy-M-d");
dformat.setLenient(false);
Date cin = dformat.parse(cinDate);
和sql函数
create or replace function search(_checkIn date, _checkOut date) returns setof Bookings as $$
declare
r Bookings;
begin
for r in
select * from Bookings
loop
if ((_checkIn between r.checkIn and r.checkOut) or (_checkOut between r.checkIn and r.checkOut)) then
return next r;
end if;
end loop;
return;
end;
$$ language plpgsql;
postgresql 的日期格式是标准的(默认)
create table Bookings (
id serial,
status bookingStatus not null,
pricePaid money not null,
firstName text,
lastName text,
address text,
creditCard text,
checkOut date not null,
checkIn date not null,
room integer not null,
extraBed boolean not null default false,
foreign key (room) references Rooms(id),
primary key (id)
);
我正在尝试将日期解析到函数中,以便它可以为我返回一个表,我似乎遇到了日期格式的问题(这就是我认为我收到此错误的原因)
org.postgresql.util.PSQLException: ERROR: syntax error at or near "Feb"
所以我想知道如何解决这个问题,我不知道如何正确格式化日期
编辑:
我正在调用这样的查询
try {
String searchQuery = "SELECT * FROM Rooms r where r.id not in (select * from search(" + cin +", " + cout +"))";
PreparedStatement ps = conn.prepareStatement(searchQuery);
rs = ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
所以我认为出现错误是因为我格式化日期的方式是错误的,postgres 不会读取它