0

Yes, there are alot of post on this topic, but all of them seem to be in regards to inserting data. I am in need of pulling data.

I just found what the problem is but I have not found out how to write it out correctly. have a prepared statement that I found in one of our projects that does not work.

I have traced it down to where we are checking if a date is >= x AND <= Y.

I have been on this problem literally all day.

statement.append("SELECT error_code FROM dw.transaction_error_logs");
statement.append(" WHERE activity_timestamp >= '?'");
statement.append(" AND activity_timestamp <= '?'");

The DB is Postgres and the column is type 'timestamp with time'. I have tried it without the quotes but then I get errors with the characters being passed as the values are like '2015-11-12 17:37:45'

edjm
  • 4,830
  • 7
  • 36
  • 65
  • 1
    `statement.setDate(1, new java.sql.Date(...));`? (I think some JDBC drivers might allow a `java.util.Date`, but you'd need to check that against your drivers documentation) – MadProgrammer Nov 13 '15 at 01:31
  • Oh, and you won't need to quote the marks (`'?'`), then can just be `?` – MadProgrammer Nov 13 '15 at 01:32
  • You don't write the parameters as String in where clause. See [this answer](http://stackoverflow.com/questions/7626076/how-to-set-current-date-and-time-using-prepared-statement) as an example – vsnyc Nov 13 '15 at 01:32
  • I really don't care about the -1 vote. I have spent hours looking but not knowing what to look for makes it hard to find answers. It was all from some old projects I had dumped on me this week. – edjm Nov 13 '15 at 01:32
  • Thank you very much MadProgrammer I just figured with all of those Insert questions people were asking that it would be different as I am pulling data. – edjm Nov 13 '15 at 01:35
  • 1
    I pretty sure I do this with select statements all the time. Maybe have a look at [Using Prepared Statements](http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) – MadProgrammer Nov 13 '15 at 01:37
  • Put your answer from above as an answer so I can tag it as the answer. Thank you for putting me on the right path. – edjm Nov 13 '15 at 01:41

0 Answers0