最近在做一些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. springboot学习-springboot使用spring-data-jpa操作MySQL数据库

    我们在上一篇搭建了一个简单的springboot应用,这一篇将介绍使用spring-data-jpa操作数据库. 新建一个MySQL数据库,这里数据库名为springboot,建立user_info数 ...

  2. 【代码笔记】iOS-UITableView上的button点击事件

    代码. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController < ...

  3. JDK8下maven使用maven-javadoc-plugin插件报错

    由于JDK8的doc生成机制比之前的要严谨许多,导致项目用maven打包的时候出错 解决办法: 添加-Xdoclint:none配置 完整配置如下:   <plugin> <grou ...

  4. Retrofit+OKHttp忽略https证书验证

    记录这个的原因,是因为很多时候,因为后台配置的证书不正确导致APP访问不到服务器数据,导致影响自身的开发进度.没几行代码,逻辑也清晰,所以下面就直接贴出工具类吧: package huolongluo ...

  5. flutter row 文字显示不全

    解决:在row层中的text层加一个expend flutter Row里面元素居中显示 new Expanded( flex: , child: new Row( children: <Wid ...

  6. 如何借助 NoSQL 提高 JPA 应用性能

    [编者按]关注 NoSQL 的动态发展很重要.NoSQL 的好处并不仅限于新的应用开发.在某些案例中,你可以见识到重新访问现有的.传统的框架带来的积极效果,比如说你的 JPA 的实现.本文系国内 IT ...

  7. python之lambda函数/表达式

    lambda函数也叫匿名函数,允许快速定义单行函数.通常是在需要一个函数,但是又不想费神去命名一个函数的场合下使用,也就是指匿名函数. 格式 lambda argument_list: express ...

  8. 使用FireFox插件RESTClient、HttpRequester模拟http(get post)请求

    我们写好一个接口后,需要进行测试.有时我们会写一个html表单提交,无疑增加了工作量,尤其是当参数比较多或者传json或xml数据时,效率更是大大降低.我们可以使用基于FireFox的RESTClie ...

  9. Linux基础知识与基础命令

    Linux基础知识与基础命令 系统目录 Linux只有一个根目录,没有盘符的概念,文件目录是一个倒立的树形结构. 常用的目录功能 bin 与程序相关的文件 boot 与系统启动相关 cdrom 与Li ...

  10. Oracle EBS INV 挑库发放物料搬运单

    create or replace PROCEDURE XX_TRANSACT_MO_LINE AS -- Common Declarations l_api_version NUMBER := 1. ...