MS SQL JDBC 3.0 driver Timestamp error with Java 7
Hi all!
I found a problem with Timestamp.
From a Java program I execute the statement 'SELECT Getdate()', the result is '2011-10-11 13:10:51.333'. It is correct.
When I use a stored procedure with a datetime output parameter, the result is '2011-10-09 13:10:51.373'. The day is incorrect.
The SQL Server version is 2008 R2. JDBC driver version 3.0.1301.101.
The Java program source:
java.sql.Connection conn = DriverManager.getConnection("jdbc:sqlserver://xxx;instanceName=SQL2008R2;DatabaseName=database1;SelectMethod=cursor", "sa", "xxx");
CallableStatement cs = conn.prepareCall("{call sw_procDateTime(?)}");
cs.registerOutParameter(1, Types.TIMESTAMP);
cs.executeUpdate();
System.out.println("Incorrect date: " + cs.getTimestamp(1));
ResultSet rs = conn.createStatement().executeQuery("SELECT Getdate()");
rs.next();
System.out.println("Correct date: " + rs.getTimestamp(1));
conn.close();
The stored procedure's source:
CREATE PROCEDURE sw_procDateTime
@idopont datetime output AS
set @idopont=getdate()
When I run the program in JRE 6, both date is correct. The timestamp problem is occured only in JRE 7.
I post this problem in the MS SQL JDBC Forum (http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/ff4047ae-042c-4adb-afd2-213f0db5900b/)
They said it is a JRE problem. Any idea?
Thanks
Balazs