简体   繁体   中英

Timestamp in database query in linux vs windows on Oracle

I'm having a strange issue with some legacy code. This works when I run it in windows but not when I run it from linux.

...
ResultSet rs = st.executeQuery("SELECT MODTS from MYTBL WHERE ID = 'X'");
rs.next();
Timestamp ts = Timestamp.valueOf(rs.getString(1));
System.out.println("TS: '" + ts + "'");

PreparedStatement ps = conn.prepareStatement("SELECT * from MYTBL WHERE MODTS = ?");
ps.setTimestamp(1, ts);

System.out.println("FOUND? " + ps.executeQuery().next());

Now, both environments are connecting to the same database, both environments print out the value '2013-03-10 03:35:16.0' for the TS variable. However, in windows I get "FOUND? true" in linux I get "FOUND? false".

Any idea what could be going on here?

NOTE: I know this is not the optimal way to use JDBC here, but this is legacy code which I can't make changes to and I'm trying to figure out why it's not working properly in one environment.

The DB environment is Oracle 11g using ojdbc6.jar

EDIT: What's more strange is that this doesn't happen on ALL timestamps, just certain ones. I really don't get what is going on here...

Ok, I was able to find the solution. The problem still alludes me but this solves it at least.

Change:

ps.setTimestamp(1, ts);

To:

ps.setTimestamp(1, ts, Calendar.getInstance(TimeZone.getDefault()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM