我有一个在 Java 6、Glassfish 4.1、SQL Server 2012、Nebeans 8 下工作的 JSF Web 应用程序,但我在 Java 8、Glassfish 5.1.0、SQL Server 2014、Netbeans 12 下收到错误。它有所不同,但确实如此通常是未找到握手、套接字或类(专注于 servlet)。
握手错误:
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)
一切都在同一台机器上,我试过没有打开防火墙,所以我不相信这是一个端口问题,尽管 glassfish 服务器日志说它已连接但端口在某些配置下关闭。
我也尝试过 Payara 并在那里遇到了失败。
代码看起来很简单,所以很可能是配置/库问题,但我一直没能理清。
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";
}