Note that there are some explanatory texts on larger screens.

plurals
  1. PODate columns in SQL-Server (MSSQL-JDBC 3.0) running under Java 1.7.0 retrieved as 2 days in the past
    primarykey
    data
    text
    <p>I have strange effects when retrieving columns of type DATE from SQLServer2008 using the <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=21599">Microsoft JDBC-Driver version 3.0</a> when running under the official Oracle JDK 1.7.0. Host OS is Windows Server 2003.</p> <p>All Date columns are retrieved as <em>two</em> days in the past with respect to the value actually stored in the column.</p> <p>I cooked up a minimal code example the test this out (Test table and data):</p> <pre><code>CREATE TABLE Java7DateTest ( dateColumn DATE ); INSERT INTO Java7DateTest VALUES('2011-10-10'); </code></pre> <p>Code:</p> <pre><code>public class Java7SQLDateTest { public static void main(final String[] argv) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection connection = DriverManager.getConnection( "jdbc:sqlserver://192.168.0.1:1433;databaseName=dbNameHere", "user", "password"); PreparedStatement statement = connection.prepareStatement("SELECT * FROM Java7DateTest"); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { final java.sql.Date date = resultSet.getDate("dateColumn"); final String str = resultSet.getString("dateColumn"); System.out.println(date + " (raw: " + str + ")"); } resultSet.close(); statement.close(); connection.close(); } catch (final Throwable t) { throw new RuntimeException(t.getMessage(), t); } } } </code></pre> <p>Running this code on above configuration prints: "2011-10-08 (raw: 2011-10-08)". Under JRE 1.6.0_27 it prints: "2011-10-10 (raw: 2011-10-10)"</p> <p>I could not find anything that seems to relate to my problem with google, so I'm assuming that its either something stupid I overlooked or nobody is using Java7 yet.</p> <p>Can anybody confirm this problem? What are my alternatives if I still want to use Java7?</p> <p>Edit: The problem occurs even when running with -Xint, so its not caused by Hotspot bugs.</p> <p>Edit2: Old drivers (Microsoft 1.28) work properly with JDK1.7.0 (we were using that driver until maybe two years ago, I think). jTDS also works perfectly fine with the example. I am considering switching to jTDS, but I am reluctant to do so because I have not the faintest idea what the effects on our productive environment may be. Ideally it should just work, but that what I believed when I switched my dev box to Java7, too. There is one pretty fat database in the production environment, that is too big to create a copy of, for testing (or rather our server has so little disk left). So setting up a test environment for that one app is not straigthforward, I would have to stitch up a shrinked database for that.</p> <p>Edit3: jTDS has its own set of catches attached. I found a behavioral difference that breaks one of our applications. ResultSet.getObject() returns different object types for SmallInt columns depending on driver (Short vs Integer). Also jTDS does not implement JDBC4 Connection interface, Connect.isValid() is not supported.</p> <p>Edit4: I noticed last week that MSSQL-JDBC 3.0 refuses to connect to any DB after I updated to JDK1.6.0_29. jTDS it is then... we switched the productive server yesterday (I fixed tow places where the application was relying on peculiarities of the driver), and so far we had have no problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload