I am having trouble trying to use timestamp2 instead of Timestamp in SQL Server 2008. Obviously rs.getTimestamp has very different behavior between timestamp and timestamp2. However, I cannot find the documentation that says there should be a difference, or that I should use something else. Interesting, I'm just doing something wrong.
Environment:
- Tried both SQL Express 2008 (10.0) and SQL Server 2008 R2 (10.5).
- sqljdbc4.jar version 3.0, size 537,303 bytes, CRC-32 = a0aa1e25, MD5 = 402130141d5f2cee727f4371e2e8fd8a.
- Java 1.6
Here is a unit test example demonstrating the problem. The only "magic" is "Db.getConnection ()", which you can replace with the appropriate code. The test is the same as for datetime, and for datetime2, but the datetime2 test failed with a date earlier than 2 days. I process all times in the database as GMT / UTC, and I did not try to add time zone information to the database data for datetime2 data.
private void testTimestamp(TimeZone gmtTz, Connection conn, String query, Calendar expectedCal) throws SQLException { PreparedStatement stmt = conn.prepareStatement(query); ResultSet rs = stmt.executeQuery(); while (rs.next()) {
Is my only option switching to timestamp?
EDIT: for future Googlers, using sqljdbc4.jar version 3.0, the test does not work on Linux, but passes through Windows. I have not tried the version of sqljdbc4.jar 4.0 that ships with SQL Server 2012.
Pixel source share