title: LocalDateTime and SQL Server JDBC 4.2 driver
body: <p>I'm trying to use new <code>java.time</code> classes with most recent version of Sql Server JDBC driver. As I read it should just work with methods: <code>PreparedStatement.setObject()</code> and <code>ResultSet.getObject()</code>.</p>
  
  <p>So I created sample code, and can't get it work with ResultSets. I don't know what I'm doing wrong here.</p>
  
  <pre><code>Connection connection = DriverManager.getConnection(connectionString);
  PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM myTable WHERE ? BETWEEN date_from AND date_to");
  preparedStatement.setObject(1, LocalDateTime.now());   // That works
  
  ResultSet resultSet = preparedStatement.executeQuery();
  if (resultSet.next()) {
      Object o = resultSet.getObject("date_from"); 
      o.getClass() returns java.sql.Timestamp
  
      LocalDateTime dateTime = resultSet.getObject("date_from", LocalDateTime.class);
  }
  </code></pre>
  
  <p>This throws an exception:</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: The conversion to class java.time.LocalDateTime is unsupported.</p>
  </blockquote>
  
  <p>Driver version: mssql-jdbc-6.5.4.jre8-preview.jar</p>
  
  <p>SQL Server version: 2016</p>
  
  <hr>
  
  <p><a href="https://docs.microsoft.com/en-us/sql/connect/jdbc/jdbc-4-2-compliance-for-the-jdbc-driver?view=sql-server-2017" rel="noreferrer">https://docs.microsoft.com/en-us/sql/connect/jdbc/jdbc-4-2-compliance-for-the-jdbc-driver?view=sql-server-2017</a></p>
  
  <p>How to interpret this sentence in table at bottom:</p>
  
  <p>New Java classes in Java 8:
  LocalDate/LocalTime/LocalDateTime,
  OffsetTime/OffsetDateTime</p>
  
  <p>New JDBC types:
  TIME_WITH_TIMEZONE,
  TIMESTAMP_WITH_TIMEZONE,
  REF_CURSOR</p>
  
  <p><code>REF_CURSOR is not supported in SQL Server. Driver throws a SQLFeatureNotSupportedException exception if this type is used. The driver supports all other new Java and JDBC type mappings as specified in the JDBC 4.2 specification.</code></p>