I've looked around and could not seem to find this asked specifically, on SO, but I've found similar questions like this one and lots of questions regarding SQL itself or C#...
Here is what I am seeing:
MapSqlParameterSource parameterSource = new MapSqlParameterSource(); //parameterSource.addValue( "insertDate", DateTime.now().minusHours( 1 ).toGregorianCalendar(), Types.TIME ); parameterSource.addValue( "insertDate", new Timestamp( DateTime.now().minusHours( 1 ).getMillis() ) ); List< String > contents = _simpleJdbcTemplate .query( "SELECT TOP (200) inserteddatetime, Contents FROM dbo.tsomeTable WHERE (ServiceName = 'something') and inserteddatetime > :insertDate", new RowMapper< String >() { @Override public String mapRow( final ResultSet rs, final int rowNum ) throws SQLException { System.out.println( rs.getTimestamp( "inserteddatetime" ) ); return rs.getString( "Contents" ); } }, parameterSource ); The query "hangs"\does nothing\never returns if:
- I use the uncommented Timestamp object (as presented above)
- I replace the
parameterSourceobject withDateTime.now().minusHours( 1 ).toGregorianCalendar()orDateTime.now().minusHours( 1 ).toGregorianCalendar().getTime() - I try the commented out line, but change the type to
Timestamp
So, here is my question or questions...
Is there a known bug\issue with querying on datetime columns in sql server?
Why do I have to use Time and not Timestamp?
I suspect that Spring is converting the date objects over to Timestamp when I query with the object directly (as demonstrated in #2).