0
votes

I am trying to connect to sqlserver 2017 using jdbc driver (microsoft 4.2 and 7.1) jdk 1.8_201. Windows 10

String connectionUrl = "jdbc:sqlserver://localhost\\SQLEXPRESS01;integratedSecurity=true;";
         Random r = new Random();
         try(Connection connection = DriverManager.getConnection(connectionUrl)) {
}

I got the following exception :

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Connection reset by peer: socket write error ClientConnectionId:16429365-183f-44fc-a599-c66fe7ad39be". at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2887) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1881) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2452) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2103) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1950) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1162) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:735) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Autofill.main(Autofill.java:50) Caused by: java.io.IOException: Connection reset by peer: socket write error ClientConnectionId:16429365-183f-44fc-a599-c66fe7ad39be at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:780) at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:840) at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:833) at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:1003) at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:993) at sun.security.ssl.InputRecord.readFully(Unknown Source) at sun.security.ssl.InputRecord.read(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1799) ... 8 more

It is connected well with sqlcmd and SSMS, even though with Odbc

I cannot use Odbc driver since it is removed from jdk 8 and I don't have currently the old version 7 to connect with Odbc driver

1

1 Answers

-2
votes

DriverManager.getConnection("jdbc:mysql://localhost:3306/DB?useLegacyDatetimeCode=false&serverTimezone=UTC", "USER", "PW");

I use mysql so I dont know how it works with sqlserver. (still learning it) But in mysql you have to specify a user and password. Maybe thats the problem.

LG RT