The driver cannot establish a secure connection with SQL Server by using secure sockets layer (SSL) encryption. Error: "no approve protocol (protocol is disabled or cipher"

Keywords: SQL Server Eclipse JDBC

This article solves the following exception information, hoping to be helpful to your programming!

Abnormal information

The driver cannot establish a secure connection with SQL Server by using secure sockets layer (SSL) encryption. Error: "no appropriate protocol (protocol is disabled or cipher suits are inappropriate)"“

Operating environment

JDK/JRE:1.8.0_212
Compiler: Eclipse 2021-06 (4.20.0)
SQL SERVER: 2008

Exception description

The following error occurred when connecting to SQL SERVER using JDBC

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The driver cannot use secure sockets layer(SSL)Encryption and SQL Server Error establishing secure connection:"No appropriate protocol (protocol is disabled or cipher suites are inappropriate)". 
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1368)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1412)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1058)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at Main.main(Main.java:16)
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
	at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:172)
	at java.base/sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
	at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:238)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:444)
	at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:422)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1379)
	... 7 more

Error reason

It may be caused by the mismatch between the encryption algorithm of JRE and that of SQL SERVER, and the latest version of Eclipse uses its own JRE. Therefore, the error may be caused by the mismatch between the encryption algorithm of JRE in Eclipse and that of SQL SERVER, resulting in connection failure

resolvent

Because there is a problem with the JRE in Eclipse, we only need to switch the JRE of Eclipse to our own JRE. The steps are as follows:

Add JRE in Eclipse

open
Eclipse -> Window -> Perferences -> Java -> Installed JREs
The following interface appears

The first is the JRE provided by Eclipse (an error will be reported when connecting to SQL SERVER)
The second one I added later will show you how to add JRE.

Select the "Add" button on the right side of the interface above


If you forget the JDK installation path, you can open the command line and enter the following commands to view it

echo %JAVA_HOME%

Select jre folder


This completes the addition of the JRE of Eclipse. To be used in the project, you need to configure the following:

Modify JRE version in project




Here, we must choose the JRE with version number. This is the JRE that comes with our own JDK, not the JRE that comes with Eclipse.
At this point, the JRE modification of the project has been completed. You can test whether your project will still have exceptions.
—END—
When creating a new project, you can specify the JRE first, so you don't have to configure the JRE version manually. If it's troublesome, you can directly delete the JRE configuration in Eclipse in the add JRE interface (see Figure 2 below)

Posted by feidakila on Sun, 05 Dec 2021 16:15:32 -0800