title: Java 1.8.0 enable TLS1.2 in JDBC connection
body: <p>I have an SQL Server 2014 updated to the latest fixpack (<strong>12.0.5207</strong>). In the environment, the only protocol enabled is TLS1.2 (the registry keys has been set for the purpose). I can connect to the SQL server using the SA account both locally and remotely using Management Studio.</p>
  
  <p>However when I try establishing a connection to the SQL server using java code and the JDBC driver <strong>sqljdbc42.jar</strong> the following exception is thrown:</p>
  
  <blockquote>
    <p>The driver could not establish a secure connection to SQL Server by
    using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did
    not return a response. The connection has been closed.</p>
  </blockquote>
  
  <p>The java code is the following:</p>
  
  <pre><code>public static void main(String[] args) 
  {
      try 
      {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
      }
      catch (ClassNotFoundException e) 
      {
          System.out.println( e.toString() ); 
      }
  
      String connectionUrl =  "jdbc:sqlserver://localhost:1433;" +  
                              "databaseName=TRCDB;user=sa;password=**********;";  
      try 
      {
          Connection con = DriverManager.getConnection(connectionUrl);
      } 
      catch (SQLException e) 
      {
          System.out.println( e.toString() ); 
      } 
  }
  </code></pre>
  
  <p>When the JVM is launched the following option are passed:</p>
  
  <pre><code>-Djavax.net.debug=all -Djdk.tls.client.protocols="TLSv1.2" -Dhttps.protocols="TLSv1.2"
  </code></pre>
  
  <p>So although only TLSv1.2 is enabled the "Client Hello" is done using TLSv1:</p>
  
  <pre><code>jdk.tls.client.protocols is defined as TLSv1.2 SSLv3 protocol was requested but was not enabled 
  SUPPORTED: [TLSv1, TLSv1.1, TLSv1.2] 
  SERVER_DEFAULT: [TLSv1, TLSv1.1, TLSv1.2] 
  CLIENT_DEFAULT: [TLSv1.2] 
  ...
  *** ClientHello, TLSv1
  ...
  main, WRITE: TLSv1 Handshake
  ...
  main, called close()
  main, called closeInternal(true)
  main, SEND TLSv1.2 ALERT:  warning, description = close_notify
  main, WRITE: TLSv1.2 Alert, length = 2
  </code></pre>
  
  <p>Is it the <strong>TLS</strong> version the root cause of the problem?
  How can I force <strong>TLSv1.2</strong>?</p>