0

I have meet a very weird situation. I use Eclipse to connect to a remote SQL Server 2008 database, and I get the correct date. But when my colleague copies the code and runs it, all the dates are 2 days earlier than they should be. For example, I get 2011-02-22 and he gets 2011-02-20.

A lot of thanks!

String test = "select * from Readings";
ResultSet set = state.executeQuery(test);
while (set.next()) {
    String row="";for(int i=1;i<10;i++){
        row += set.getString(i) + ",";
        arr.add(row);
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Are you connecting to the same database? – Branko Dimitrijevic Feb 22 '12 at 04:36
  • yes, exactly the same code, and the database is not local. – user1224913 Feb 22 '12 at 04:37
  • 1
    I'm not asking about _code_. I'm asking about database _connection_. Are you both using the same connection string? And even if you do, do they actually point to the same database server (e.g. same host names may identify different machines on different networks). – Branko Dimitrijevic Feb 22 '12 at 05:04
  • I'm betting Branko is right. This is a classic symptom of hitting two different databases (for example dev/test) – JohnFx Feb 22 '12 at 05:23
  • I'm a colleague of the person asking the question (not the same one he mentions though). They are both using the same connection string and connecting to the same database server. When they run the code above, every value in every row is identical except for the dates all being 2 days earlier on one machine. Also, the data type of the field in the database table is "date", not "nvarchar(MAX)" or anything like that. The system time on all three machines is the same. – Kylar Feb 22 '12 at 05:30
  • possible duplicate of [Date columns in SQL-Server (MSSQL-JDBC 3.0) running under Java 1.7.0 retrieved as 2 days in the past](http://stackoverflow.com/questions/7724258/date-columns-in-sql-server-mssql-jdbc-3-0-running-under-java-1-7-0-retrieved-a) – richardtallent Feb 22 '12 at 06:15

1 Answers1

1

Date columns in SQL-Server (MSSQL-JDBC 3.0) running under Java 1.7.0 retrieved as 2 days in the past

I believe this is a duplicate

Community
  • 1
  • 1
richardtallent
  • 34,724
  • 14
  • 83
  • 123
  • yes, connect to the same database, and the same connecting string. it is same as the Kylar says, but why is dates are all being 2days earlier. – user1224913 Feb 22 '12 at 22:37