0

I am working on requirement where I need to query Hbase database using Phoenix JDBC driver. The exact query look like

String sql="SELECT * FROM Part_Data WHERE server = ? AND process = ? AND event_utc <= ?  ORDER BY event_utc DESC LIMIT 3";  

    statement = connection.prepareStatement(sql);
    statement.setString(1, server);
    statement.setString(2, process);
    statement.setTimestamp(3, event_utc);

The actual event_utc param passed to this query is '2017-01-13 05:36:59' But in debug logger the param value is changing to '2017-01-13 10:36:59' and pulling unexpected results from database.

My requirement is to pass the exact value '2017-01-13 05:36:59' to the query instead of formatted value with timezone ( assuming jdbc driver will do this). Please help me in resolving this

  • 2
    But the TZ matters; if you don't explicitly specify the TZ it will (generally) default to the TZ of the shell/whatever you're running it in. If the TZ in the DB doesn't match it's probably being converted to UTC/GMT. – Dave Newton Feb 20 '17 at 21:07
  • But a a process will invoke my application (RESTful) whenever a new row added to database. My requirement is to get most recent two along with the one which is recently added. I have to use exact timestamp coming as a query param to my service. – Rohith Kammula Feb 20 '17 at 21:43
  • Then you'll need to convert the TZ and hope you guess right. – Dave Newton Feb 20 '17 at 22:22
  • You need to use [`setTimestamp(int, java.sql.Timestamp, java.util.Calendar)`](http://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html#setTimestamp-int-java.sql.Timestamp-java.util.Calendar-) where the Calendar object has the right timezone. – Mark Rotteveel Feb 21 '17 at 13:19

0 Answers0