-1

My application is connected to MSSQL Server 2014 and is developed using Java 8(zulu 8u332-8.62.0.19). The database do not have SSL enabled.

The following error appears: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]".

for me, to enable TLS12 on database in not a possible solution; neither to enable TLS10 into my application;

  • 3
    Why can't you add TLS1.2 to SQL Server? SQL server 2014 had TLS 1.2 Support added in [KB3135244](https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe), and was supported on SP1 CU5 or RTM CU12 onwards, and was released way back in 2016; have you not updated your server yet? TLS1.0 is *long* unsupported now. – Thom A Sep 01 '22 at 12:06
  • You need to install the relevant KB as linked above (preferably the latest build instead https://sqlserverbuilds.blogspot.com/2014/01/sql-server-2014-versions.html) also you need to install relevant operating system updates for TLS 1.2 if you are on Windows 7 or Windows Server 2012 R2 – Charlieface Sep 01 '22 at 13:37
  • I can not make changes on db side. I have to find a workaround. What I see so far is that there is an incompatibility between MSSQL 2014 and java8-332. – junior-java-dev Sep 01 '22 at 14:17

1 Answers1

0

first you have to include the connector jar file in your library, mssql-jdbc-10.2.1.jre8.jar works well with java 8, then if your sql server doesn't have a password you can use this code

public Connection getConnection() {
           Connection conn = null;
           try{
               Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
               if(conn==null)  conn= DriverManager.getConnection("jdbc:sqlserver://your_server_name; databaseName=name_of_the_database_you_use;integratedSecurity=true;" +
                       "trustServerCertificate=true;IntegratedSecurity=true;");
          
               }


            catch (Exception ex) {
              ex.printStackTrace();

           }
        return conn;
    }
sam
  • 21
  • 2
  • Thank you for your answer. I have already tried to change the jdbc version but it does not work. About passing the parameters via URL, it also does not change the behavior. – junior-java-dev Sep 01 '22 at 13:26