赞
踩
.
.
对应的版本号最好要使用对应的mysql驱动jar包,例如:
Exception in thread "main" java.sql.SQLException: Unknown system variable 'query_cache_size'
运行时会出现这样的异常,此异常就是代表驱动jar包的版本与mysql的版本不兼容。
解决办法:更换与mysql版本兼容的驱动jar包
.
.
显示下面异常
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
异常的原因是com.mysql.jdbc.Driver这个驱动已经不能用了,要按照提示用新的驱动。 5.几版本的mysql好像是没有这个问题的,高版本的因为更新的较多的方法所以需要用新提供的驱动。
解决方法:依照提示的信息使用新的驱动。如提示中显示The new driver class is `com.mysql.cj.jdbc.Driver’ 则将原本的驱动替换成为com.mysql.cj.jdbc.Driver即可
由于mysql内置使用的是0时区,我们中国这边则是东八区
刚安装好的mysql需要修改时区,否则会报以下异常
The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrec
解决方法1:直接在mysql执行语句:
set global time_zone=’+8:00’
.
解决方法2:修改配置文件
找到my.ini, 在mysqld 下增加 default-time-zone = ‘+8:00’
必须放到mysqld 下,放入其它位置无效
.
.
我们经常看到一下错误
Sat Jul 25 13:25:02 CST 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. 1 Sat Jul 25 13:25:04 CST 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:307) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:254) 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:1284) at com.mysql.cj.NativeSession.quit(NativeSession.java:182) at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1911) at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:730) at com.lele.demo.jdbc_demo1.main(jdbc_demo1.java:20) ** END NESTED EXCEPTION ** Process finished with exit code 0
虽说这对初学者程序的运行没有多大的影响,但是看到那么一大段的错误提示就非常的烦。
原因是使用高版本的mysql时需要指明SSL连接
解决方法:在获取数据库连接对象时的url后面加上?useSSL=true或者?useSSL=false如
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_book?useSSL=false", "xx", "xx");
加上后异常就会解决
.
.
.
.
.
.
以上为本人学习时的记录或遇到的问题,如有侵权,请联系立即删除
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。