最近在做一些java web整合时使用的最新版Mysql8.0.3,发现Mysql连接中的几个问题,总结如下:

package db;//自定义包名
import java.sql.*; public class test1 { public static void main(String[] args) {
// TODO Auto-generated method stub
String user="root";
String password="123456";
String url="jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC";//mydb为Mysql数据库中创建的数据库实例名
String driver="com.mysql.cj.jdbc.Driver"; String tableName="studinfo";//studinfo为数据库mydb中的表名
String sqlstr;
Connection con=null;
Statement stmt=null;
ResultSet rs=null; try
{
Class.forName(driver);
con=DriverManager.getConnection(url, user, password);
stmt=con.createStatement(); sqlstr="insert into "+tableName+ " value('1111','honey',21)";//into的后面和value前面一定要添加一个空格;value后面与左括号之间有无空格无所谓。
stmt.executeUpdate(sqlstr); sqlstr="select * from "+ tableName;
rs=stmt.executeQuery(sqlstr); ResultSetMetaData rsmd=rs.getMetaData();
int j=0;
j=rsmd.getColumnCount();
for(int k=0;k<j;k++)
{
System.out.print(rsmd.getColumnName(k+1));
System.out.print("\t");
} System.out.println(); while(rs.next())
{
for(int i=0;i<j;i++)
{
System.out.print(rs.getString(i+1));
System.out.print("\t");
}
System.out.println();
}
}
catch(ClassNotFoundException e1)
{
System.out.print("数据库驱动不存在!");
System.out.print(e1.toString());
}
catch(SQLException e2)
{
System.out.print("数据库存在异常!");
System.out.print(e2.toString());
}
finally
{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}
catch(SQLException e)
{
System.out.print(e.toString());
}
}
}
}

  常见错误提示1:

  以上配置中,url中如果driver没有添加cj,则会在连接的时候出现以下错误提示:

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.

  解决办法:根据提示,很显然这种driver配置方式在此版本中已经被废弃,因此需要将driverClass配置为:com.mysql.cj.jdbc.Driver。

  常见错误提示2:

  以上配置中,url中如果没有设置useSSL=false,则会在连接的时候出现以下错误提示:

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.

  解决办法:在连接字符串中添加?useSSL=false

  常见错误提示3:

  以上配置中,url中如果没有设置serverTimezone=UTC,则会在连接的时候出现以下错误提示:

The server time zone value '???ú±ê×??±??' 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.

  解决办法:在连接字符串中添加&amp;serverTimezone=UTC

  常见错误提示4

  错误提示:对实体 "serverTimezone" 的引用必须以 ';' 分隔符结尾。

  解决办法:在 xml 中 &符号是作为实体字符形式存在的。故需要在连接字符串中的将ServerTime前面的&符号修改为&amp;,参见上面的代码。

初学者在Mysql8.0连接时的几个常见基本问题的更多相关文章

  1. 错误档案2:MySQL8.0连接C3P0的问题

    >>>跳过BB,空降正文<<< 目录 前言 问题出现 解决方法 结论 前言 大家好呀,我是 白墨,一个热爱学习与划水的矛盾体. 前两天在使用C3P0连接池时遇到问题 ...

  2. maven 项目连接mysql8.0版本时的注意事项

    MySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 以前的maven项目,要注意依赖的注入 查看pom. ...

  3. Navicat连接MySQL8.0版本时 建议升级连接客户端这个提示怎么办

    开始->mysql 8.0 command line client ->执行下面的命令//开启mysql服务mysql.server start//进入mysqlmysql -u root ...

  4. mysql8.0安装时,Unable to connect to any of the specified MySQL hosts

    https://blog.csdn.net/u014776759/article/details/88422967

  5. VMware workstation16 中Centos7下MySQL8.0安装过程+Navicat远程连接

    1.MySQL yum源安装 2.安装后,首次登录mysql以及密码配置3.远程登录问题(Navicat15为例) 一.CentOS7+MySQL8.0,yum源安装1.安装mysql前应卸载原有my ...

  6. win10安装两个不同版本的mysql(mysql5.7和mysql-8.0.19)

    win10中安装mysql5.7后,安装mysql-8.0.19 在D:\mysql-8.0.19-winx64目录下创建一个my.ini文件 [mysqld] # 设置3307端口 port # 设 ...

  7. mysql8.0新增用户及密码加密规则修改

    MySQL8.0已经发布GA版,当前最新GA版本为8.0.12.虽然相对于之前版本,MySQL8.0没有加入新元素,但是,经过代码重构,MySQL8.0的优化器更加强大,同时也有一些新特性,如支持索引 ...

  8. 远程连接mysql8.0,Error No.2058 Plugin caching_sha2_password could not be loaded

    通过本地去连接远程的mysql时报错,原因时mysql8.0的加密方法变了. mysql8.0默认采用caching_sha2_password的加密方式 第三方客户端基本都不支持这种加密方式,只有自 ...

  9. 登录注册页面(连接MySQL8.0.15版本)

    原文链接:https://mp.weixin.qq.com/s?__biz=MzI4Njg5MDA5NA==&mid=2247483779&idx=1&sn=e23e68e96 ...

随机推荐

  1. ActivityManagerService原理&源码

    https://www.kancloud.cn/alex_wsc/android-deep2/413386 http://wiki.jikexueyuan.com/project/deep-andro ...

  2. python学习之老男孩python全栈第九期_day010知识点总结

    def qqxing(l = []): # 可变数据类型 l.append(1) print(l)qqxing() # [1]qqxing([]) # [1]qqxing() # [1, 1]qqxi ...

  3. Java 取得文件名的后缀

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 文件上传的时候可能需要修改文件名,因此需要取得文件的后缀: String filename="123.t ...

  4. 【代码笔记】iOS-SDWebImage的使用

    一,工程图. 二,代码. RootViewController.m #import "RootViewController.h" //加入头文件 #import "UII ...

  5. Linux CentOS 6.5 下 vsftpd ftp服务器搭建

    Linux CentOS 6.5 下 vsftpd ftp服务器搭建 by:授客 QQ:1033553122   操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.ce ...

  6. View的draw机制

    View:1.draw//绘制一个View以及他的子View.最好不要覆写该方法,应该覆写onDraw方法来绘制自己.public void draw(Canvas canvas); public v ...

  7. Android逆向 APK文件组成

    一 了解APK文件 我们知道Android系统能运行的程序是.apk文件格式,其实它就是一个压缩包而已,把.apk修改成.zip,然后解压就可以得到该apk内部的文件结构. PS: 既然可以把apk文 ...

  8. [Linux]《鸟哥的私房菜》笔记 (缓慢更新)

    暂时不更新了..这几天一看起书来发现内容很多,这样写blog太慢,也没意义.所以现在是每天看书,在笔记本上记笔记,再配合着<操作系统>和 linux内核 加深理解.往后会以心得体会为主写一 ...

  9. 【Python】爬取网站图片

    import requests import bs4 import urllib.request import urllib import os hdr = {'User-Agent': 'Mozil ...

  10. windows无法访问linux服务器

    解决: 或者有效 iptables -A INPUT -p tcp --dport 8000 -j ACCEPT[root@localhost ~]# iptables -A OUTPUT -p tc ...