jdbc query - date ranges as parameters

Posted by pstanton on Stack Overflow See other posts from Stack Overflow or by pstanton
Published on 2010-03-17T06:16:34Z Indexed on 2010/03/17 6:21 UTC
Read the original article Hit count: 327

Filed under:
|
|
|

Hi all,

I'd like to write a single JDBC statement that can handle the equivalent of any number of NOT BETWEEN date1 AND date2 where clauses.

By single query, i mean that the same SQL string will be used to create the JDBC statements and then have different parameters supplied.

This is so that the underlying frameworks can efficiently cache the query (i've been stung by that before).

Essentially, I'd like to find a query that is the equivalent of

SELECT * FROM table WHERE mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ?

and at the same time could be used with fewer parameters:

SELECT * FROM table WHERE mydate NOT BETWEEN ? AND ?

or more parameters

SELECT * FROM table WHERE mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ? AND mydate NOT BETWEEN ? AND ?

I will consider using a temporary table if that will be simpler and more efficient.

thanks for the help!

© Stack Overflow or respective owner

Related posts about jdbc

Related posts about postgresql