Java 7 connection to Sql Server 2014

0

I am trying to connect with java 7 to sql server 2014 and I get the following error:

  

The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server returned an incomplete response." The connection has been closed. "

the code I'm using is:

driver ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
url ="jdbc:sqlserver://Ip:port;databasename=xxx";
user = "xxx";
pass = "xxx";
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pass);

Download the .jar files from Msdn download Msdn Downloads and I used : sqljdbc.jar, sqljdc4.jar, sqljdbc41.jar and sqljdbc42.jar.

Thanks in advance.

    
asked by Ivan Fontalvo 01.11.2016 в 16:52
source

1 answer

2

I recommend using link for what you need. And the flaw that appears is because your connection is not making it via SSL but simply by the socket.

According to the microsoft documentation you will have to add the following in your connection:

String connectionUrl =   
    "jdbc:sqlserver://localhost:1433;" +  
     "databaseName=AdventureWorks;integratedSecurity=true;" +  
     "encrypt=true; trustServerCertificate=false;" +  
     "trustStore=storeName;trustStorePassword=storePassword";  

Or it could be like this

String connectionUrl =   
    "jdbc:sqlserver://localhost:1433;" +  
     "databaseName=AdventureWorks;integratedSecurity=true;" +  
     "encrypt=true; trustServerCertificate=false;" +  
     "trustStore=storeName;trustStorePassword=storePassword" +  
     "hostNameInCertificate=hostName";  

Here is the documentation: link

    
answered by 01.11.2016 / 16:58
source