-1

i asked this question before but got no answers, i think mainly because it was a mess, i'll state the facts and put some quotes from the code under

  • im using VMWare, and have one Windows Server 2003 with SQL Server 2005 on it, with a SQL Login, and it has a DNS Service running
  • i also have a windows 7 machine running NetBeans8.2 with JDK 8.1, using JDBC 4.2
  • i can connect to the server using SQL Manager from the Windows 7 machine
  • i can't connect using the java code because of an SSL Error, i am not sure what is causing it
  • this is for a school project so i must use SQL server 2005

here's my connection code :

    package connectbd;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    
    public class ConnectBD {

    public static void main(String[] args) {

        String jdbcurl;
        Connection con = null;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        jdbcurl = "jdbc:sqlserver://SQLSERVER;instanceName=SQLE;user=****;password=****;database=DBGR15";
        
        try {
            con=DriverManager.getConnection(jdbcurl);
            System.out.println("Connection success");
        } catch(SQLException e) {
                e.printStackTrace();
        }
    }
    }

This is the error that i get :

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to the SQL Server using Secure Sockets Layer (SSL) encryption. Error: "The SQL Server server returned no response. The connection has been closed. ClientConnectionId ».
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2826)
    ****at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1829)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2391)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2042)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1889)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1120)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:700)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at connectbd.ConnectBD.main(ConnectBD.java:35)
Caused by: java.io.IOException: 
The SQL Server server returned no response. The connection was closed. ClientConnectionId
    ****at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:786)
    at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:836)
    at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:829)
    at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:999)
    at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:989)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
    at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1756)
    ... 8 more
BUILD SUCCESSFUL (total time: 1 second)

i believe the causes are somewhere in these 2 lines: the ones marked by **** at the start

i have to deliver a webservices project for school in 2 weeks, and this is kind of a huge obstacle, any quick help or suggestion would be very appreciated

2
  • [1] From your post I'm not sure whether you are asking why the SSL connection isn't working, or why your connection is using SSL. Can you clarify? [2] You stated you "can connect to the server using SQL Manager from the Windows 7 machine", but can you confirm that you can do that at the same time that your project fails to connect? I'm only asking because the error you are getting could simply be because SQL Server wasn't running. [3] Is your SQL Server using a self-signed certificate? [4] What is the name of the JDBC driver are you using? Commented Dec 7, 2018 at 2:06
  • That's good news, but your post stated "i must use SQL server 2005"?! Commented Dec 8, 2018 at 21:08

1 Answer 1

4

You will need to add few parameters to specify the ssl connection, such as integratedSecurity=true, encrypt=true and trustServerCertificate=true.

jdbcurl = "jdbc:sqlserver://SQLSERVER;instanceName=SQLE;user=****;password=****;database=LP_SIBD_GR15;integratedSecurity=true;encrypt=true;trustServerCertificate=true";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.