0

I have a table with one timestamp column . When i try to execute a date filter using this timestamp column it doesn't give any results. Table structure and code segment is follows.

create table status_well
( wid int, data_time timestamp,
primary key (wid ,data_time) )

SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
PreparedStatement statement = session.prepare("select  from status_well where data_time>? and data_time<?");
BoundStatement boundStatement=new BoundStatement(statement);    
statement.setDate("data_time", DATE_FORMAT.parse("2015-05-01"));
statement.setDate("data_time", DATE_FORMAT.parse("2015-05-10"));

Data is there for the above specified date range but no data returns . I tried with a string instead of DATE_FORMAT.parse("2015-05-01") but that gives an invalid type error .

Please advise me on this.

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23

1 Answers1

1

There are two placeholders for the data_time column, so you need to use index-based setters, or named placeholders:

PreparedStatement statement = session.prepare("select * from status_well "
    + "where wid = :wid "
    + "and data_time > :min and data_time < :max");
BoundStatement boundStatement = new BoundStatement(statement)
    .setInt("wid", 1)
    .setDate("min", DATE_FORMAT.parse("2015-05-01"))
    .setDate("max", DATE_FORMAT.parse("2015-05-10"));

(also added a restriction on wid to get a valid CQL query, as was mentioned in the comments)

Olivier Michallat
  • 2,302
  • 11
  • 13