JDBC - Prepared statements and PostgreSql Time/Date operations - Mailing list pgsql-general

From Jan Bilek
Subject JDBC - Prepared statements and PostgreSql Time/Date operations
Date
Msg-id 004201c7998c$af3cb150$0100a8c0@ook
Whole thread Raw
Responses Re: JDBC - Prepared statements and PostgreSql Time/Date operations
List pgsql-general
Hello,
 
I've got following problem:
 
I use this simple query:
 
select * from mytable where creation_time > (CURRENT_TIMESTAMP - interval '7 days');
 
---> it selects all rows from mytable, which were created before one week or sooner (creation_time is column in mytable).
 
I would like to use this query in java PreparedStatement, where age of a row would be one of its parameters:
 
PreparedStatement could look like this:
select * from mytable where creation_time > (CURRENT_TIMESTAMP - ?)
 
But nothing works with PreparedStatements!
I tried to set whole interval strings "interval '7 days'" as a parameter
I tried to set time strings '7 days' as a parameter
I tried to use BigDecimal as a parameter...
 
So, my question is: how to dynamically set time interval values to PreparedStatements and how to apply them to my example?
I've searched PostgreSql and Java docs, but i haven't find any cure.
 
Thanks for help.
 
JB
 

pgsql-general by date:

Previous
From:
Date:
Subject: Random Sample
Next
From: "Martin Gainty"
Date:
Subject: Re: JDBC - Prepared statements and PostgreSql Time/Date operations