记一次java中连接数据库时出现的问题
public class JDBCDemo {
public static void main(String[] args) throws Exception {
//获取数据库连接对象
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mjh","root","admin");
String sql = "update coures set scores=90 where snum=20181";
Statement stmt = con.createStatement();
int count = stmt.executeUpdate(sql);
System.out.println(count);
stmt.close();
con.close();
}
}
然后出现这样的情况
错误提示
Mon Jun 15 17:28:58 HKT 2020 WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
3
Mon Jun 15 17:28:59 HKT 2020 WARN: Caught while disconnecting…
EXCEPTION STACK TRACE:
** 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:133)
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:311)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:267)
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:801)
at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:780)
at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:2249)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4232)
at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1472)
at cn.mjh.JDBCDemo.main(JDBCDemo.java:16)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
** END NESTED EXCEPTION **
最终解决办法
在url后面加?useSSL=false像这样
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mjh?useSSL=false","root","admin");