Hello,
First, my code:
//------------------------ GET FIRST TIMESTAMP VALUE:
String sqlstr = "SELECT last_start_date FROM user_scheduler_jobs WHERE upper(job_name) = upper(?)";
PreparedStatement prest = c.prepareStatement(sqlstr);
prest.setString(1, jobName);
ResultSet rs = prest.executeQuery();
Timestamp startTime = new Timestamp(0);
if (rs.next()) {
startTime = rs.getTimestamp(1, Calendar.getInstance(TimeZone.getTimeZone("UTC")));
System.out.println("START_TIMESTAMP >> " + startTime); //<<<<<<<<<<<<<<<<<<<<<<<
}
//------------------------ PRINTLN SECOND TIMESTAMP VALUE:
sqlstr = "SELECT * FROM (SELECT * FROM user_scheduler_job_run_details WHERE upper(job_name) = upper(?) ORDER BY actual_start_date DESC) WHERE rownum = 1";
prest = c.prepareStatement(sqlstr);
prest.setString(1, jobName);
rs = prest.executeQuery();
if (rs.next())
System.out.println("REQ_START_DATE >> " + rs.getTimestamp("REQ_START_DATE", Calendar.getInstance(TimeZone.getTimeZone("UTC")))); //<<<<<<<<<<<<<<<<<<<<<
//------------------------ COMPARE THE TWO TIMESTAMPS (IN PL/SQL):
sqlstr = "SELECT * FROM user_scheduler_job_run_details WHERE upper(job_name) = upper(?) AND req_start_date = ?";
prest = c.prepareStatement(sqlstr);
prest.setString(1, jobName);
prest.setTimestamp(2, startTime, Calendar.getInstance(TimeZone.getTimeZone("UTC")));
rs = prest.executeQuery();
if (rs.next())
System.out.println("SUCCESS"); //<<<<<<<<<<<<<<<<<<<<<<<
I'm sorry for the wall-of-code. The SQL statements don't really matter (as you'll see in a minute), so the things that matter are really the System.out.println() calls that I've pointed out and the final PreparedStatement.
Here is my output:
START_TIMESTAMP >> 2013-01-15 16:44:27.316
REQ_START_DATE >> 2013-01-15 16:44:27.316
Basically, what this code does is it grabs a timestamp from one view and tries to compare the timestamps found in another view to it. Specifically, I'm trying to locate an entry based on timestamp. I used to not have any of those Calendar.getInstance(...) functions in there, but I googled a bit about my issue and everyone seems to suggest to use them to make sure everything is being sent around as the same timezone. In this case, what I did was I pass everything around as UTC.
The output suggests that my startTime (START_TIMESTAMP) is the same as the REQ_START_DATE found in the other view (these are the two values I'm interested in comparing); however, when I run this code and I compare the two timestamps in a PreparedStatement, it doesn't seem to find any rows (although they clearly exist, as per the PreparedStatement that is executed JUST before that one).
As you can see in my output, there is no "SUCCESS" logged, meaning it doesn't find any rows where 'req_start_date = ?'.
So, I don't get it... if the two timestamps come back identical, then why is the third statement that compares them failing to find anything?
Thanks.