Can't connect Java 8 (291) web application on Glassfish 5.1.0 to SQL Server 2014 instance

316 views Asked by At

I have a JSF web application that worked under Java 6, Glassfish 4.1, SQL Server 2012, Nebeans 8 but I am receiving an error under Java 8, Glassfish 5.1.0, SQL Server 2014, Netbeans 12. It varies some, but it is usually a handshake, socket, or class not found (focused on a servlet).

Hand shake error:

java.lang.NoClassDefFoundError: sun/security/ssl/HandshakeStateManager
    at sun.security.ssl.Handshaker.init(Handshaker.java:282)
    at sun.security.ssl.Handshaker.<init>(Handshaker.java:242)
    at sun.security.ssl.ClientHandshaker.<init>(ClientHandshaker.java:160)
    at sun.security.ssl.SSLSocketImpl.initHandshaker(SSLSocketImpl.java:1297)
    at sun.security.ssl.SSLSocketImpl.doneConnect(SSLSocketImpl.java:671)
    at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:551)
    at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:110)
    at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1606)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1324)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:992)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:828)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at Database.DAO.openConnection(DAO.java:48)

Everything is on the same machine, and I've tried without the firewall on, so I don't believe it is a port problem despite the glassfish server log says it connected but the port is closed under some configuration.

I also tried with Payara and met failure there.

The code seems very simple, so it is likely a configuration / library issue, but I haven't been able to sort it out.

public Connection openConnection(){
        //This try/catch should not be necessary, but the driver is not found here
        try{
            Class.forName(dbi.getDriver());
        }catch (ClassNotFoundException e){
                System.out.println("Could not load the driver");
        }
        
        try{
            connect = DriverManager.getConnection((dbi.getUrl()+dbi.getDbName()), dbi.getDbUsername(), dbi.getDbPassword());
        }catch(Exception e){
            e.printStackTrace();  //Point of failure: connect is null
        }
        
        return connect;
    }

public DbInfo(){
        driver      = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        url         = "jdbc:sqlserver://localhost";
        dbName      = ";DatabaseName=Test";
        dbUsername  = "user";
        dbPassword  = "pass";
    }
1

There are 1 answers

1
Kamurai On BEST ANSWER

It's not much of an answer, but when in doubt, then nuke everything and start again.

I deleted and removed the ODBC driver, SSMS, Netbeans, and Glassfish, and reinstalled each component. I made sure the firewall is open on TCP/UDP 1433-1434, and all the SQL Server services are running.

I made sure the ODBC driver was made available in the suggested Program Files directory. I made sure to enable SQL Server and Windows Authorization, the sa login is enabled, allow remote connections.

I copied the installed ODBC driver sqljdbc42.jar to make it available for projects. I minimized the number of jars each project was referencing, and included the Java 8 API and Java 8 Web API libraries.

I removed the sun folder from the grzzly jar in Glassfish.

I cleaned, built, and deployed each project before it began working in the problem project.