我正在创建一个webproject..我已经为此配置了jdbc领域..我需要将java servlet连接到mysql数据库。。
private static String JDBC_DRIVER = "com.mysql.jdbc.Driver", DB_URL = "jdbc:mysql://localhost/chat",
USER = "root", PASS = "public";
@OnMessage
public void onMessage(String msg, Session session) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String userId = getId(userName);
String sql = "SELECT * FROM user_relation WHERE user_id_2='" + userId + "' AND relation = 0;";
ResultSet rs = stmt.executeQuery(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
通过服务器运行程序时,出现以下错误:
**BEGIN NESTED EXCEPTION**
javax.net.ssl.SSLException
MESSAGE: closing inbound before receiving peer's close_notify
STACKTRACE:
javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
at com.mysql.cj.protocol.a.NativeProtocol.quit(NativeProtocol.java:1313)
at com.mysql.cj.NativeSession.quit(NativeSession.java:182)
at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1743)
at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:717)
at org.apache.catalina.realm.JDBCRealm.close(JDBCRealm.java:447)
at org.apache.catalina.realm.JDBCRealm.getRoles(JDBCRealm.java:615)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:404)
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:320)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:188)
at org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:153)
at org.apache.catalina.authenticator.FormAuthenticator.doAuthenticate(FormAuthenticator.java:264)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:572)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
**END NESTED EXCEPTION**
如何解决这个问题?我需要创建ssl证书吗..如果需要,怎么办?
2条答案
按热度按时间9nvpjoqh1#
错误-javax.net.ssl.sslexception:在接收到对等方的close\u通知之前关闭入站主要是因为默认情况下ssl设置为true。
你只需要设置
"?useSSL=false"
在你的代码里。sampl1是数据库的名称。
xqnpmsa82#
这是mysql jdbc驱动程序和java11的问题。看这里。这已在connector/j版本8.0.16中修复