【聲明:】本文是作者(蘑菇v5)原創(chuàng),版權歸作者 蘑菇v5所有,侵權必究。本文首發(fā)在簡書。如若轉(zhuǎn)發(fā),請注明作者和來源地址!未經(jīng)授權,嚴禁私自轉(zhuǎn)載!
第一個錯誤:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/itat_shop
解決辦法:
jsp容器是本地運行的tomcat,把jdbc驅(qū)動文件mysql-connector-java-version-bin.jar 拷貝到tomcat的lib文件夾下,代碼如下書寫:
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, username, password);

第二個錯誤:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '?D1ú±ê×?ê±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
解決辦法:
時區(qū)問題,在JDBC 的連接 url 部分加上 serverTimezone=UTC即可

第三個錯誤:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
解決辦法:
之前的url最后有個useSSL=true,mysql高版本中新加的一個配置項,嘗試將此配置去掉,再重啟服務,問題解決,最終的url如下所示:
String url = "jdbc:mysql://localhost:3306/itat_shop?
serverTimezone=UTC&characterEncoding=utf-8&useSSL=false";