初学者在Mysql8.0连接时的几个常见基本问题
最近在做一些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.
解决办法:在连接字符串中添加&serverTimezone=UTC
常见错误提示4:
错误提示:对实体 "serverTimezone" 的引用必须以 ';' 分隔符结尾。
解决办法:在 xml 中 &符号是作为实体字符形式存在的。故需要在连接字符串中的将ServerTime前面的&符号修改为&,参见上面的代码。
初学者在Mysql8.0连接时的几个常见基本问题的更多相关文章
- 错误档案2:MySQL8.0连接C3P0的问题
>>>跳过BB,空降正文<<< 目录 前言 问题出现 解决方法 结论 前言 大家好呀,我是 白墨,一个热爱学习与划水的矛盾体. 前两天在使用C3P0连接池时遇到问题 ...
- maven 项目连接mysql8.0版本时的注意事项
MySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 以前的maven项目,要注意依赖的注入 查看pom. ...
- Navicat连接MySQL8.0版本时 建议升级连接客户端这个提示怎么办
开始->mysql 8.0 command line client ->执行下面的命令//开启mysql服务mysql.server start//进入mysqlmysql -u root ...
- mysql8.0安装时,Unable to connect to any of the specified MySQL hosts
https://blog.csdn.net/u014776759/article/details/88422967
- VMware workstation16 中Centos7下MySQL8.0安装过程+Navicat远程连接
1.MySQL yum源安装 2.安装后,首次登录mysql以及密码配置3.远程登录问题(Navicat15为例) 一.CentOS7+MySQL8.0,yum源安装1.安装mysql前应卸载原有my ...
- 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 # 设 ...
- mysql8.0新增用户及密码加密规则修改
MySQL8.0已经发布GA版,当前最新GA版本为8.0.12.虽然相对于之前版本,MySQL8.0没有加入新元素,但是,经过代码重构,MySQL8.0的优化器更加强大,同时也有一些新特性,如支持索引 ...
- 远程连接mysql8.0,Error No.2058 Plugin caching_sha2_password could not be loaded
通过本地去连接远程的mysql时报错,原因时mysql8.0的加密方法变了. mysql8.0默认采用caching_sha2_password的加密方式 第三方客户端基本都不支持这种加密方式,只有自 ...
- 登录注册页面(连接MySQL8.0.15版本)
原文链接:https://mp.weixin.qq.com/s?__biz=MzI4Njg5MDA5NA==&mid=2247483779&idx=1&sn=e23e68e96 ...
随机推荐
- 机器人数目-2015决赛Java语言C组第一题
标题:机器人数目 少年宫新近邮购了小机器人配件,共有3类,其中,A类含有:8个轮子,1个传感器B类含有: 6个轮子,3个传感器C类含有:4个轮子,4个传感器 他们一共订购了100套机器人,收到了轮子6 ...
- Android - 富文本编辑器
Android富文本编辑器(一):基础知识 目前主流的基于Android富文本开发方式思路如下: 基于TextView图文混排 使用方式: TextView textView = new TextVi ...
- 应用rbac组件 动态生成一级菜单
动态生成一级菜单 改表结构 需要知道是否是菜单\icon\名称权限表 +字段: is_menu = models.BooleanField(max_length=32,verbose_name='是否 ...
- RBAC 介绍 (权限)
RBAC是什么? RBAC是基于角色的访问控制(Role-Based Access Control )在RBAC中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限.这就极大地简化了权 ...
- WEB服务器、应用程序服务器、HTTP服务器的区别
WEB服务器.应用程序服务器.HTTP服务器的区别 Web服务器: 基本功能就是提供Web信息浏览服务.它只需支持HTTP协议.HTML文档格式及URL.与客户端的网络浏览器配合.因为Web服务器主要 ...
- BZOJ4373: 算术天才⑨与等差数列(线段树 hash?)
题意 题目链接 Sol 正经做法不会,听lxl讲了一种很神奇的方法 我们考虑如果满足条件,那么需要具备什么条件 设mx为询问区间最大值,mn为询问区间最小值 mx - mn = (r - l) * k ...
- 【代码笔记】iOS-自定义选择框(高底强弱)
一,效果图 二,代码. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewControl ...
- 前端开发笔记(4)css基础(下)
标签定位 相对定位 相对定位是用来微调元素位置的,让元素相对于原来的位置进行调整. <head> <meta http-equiv="Content-Type" ...
- 研发环境 chrome谷歌浏览器和firefox火狐浏览器解决跨域问题
1 火狐浏览器 (1).先在地址栏输入about:config,然后单击“我了解此风险”. (2).找到security.fileuri.strict_origin_policy,然后在值下面的tru ...
- SharePoint designer workflow给一个hyperlink类型得field赋值, How to set value to a hyperlink field by designer workflow
通过worlfow给一个链接类型得field赋值: 格式是: {link}, {linkDisplayname} 一定要注意逗号后面有个空格. 举个栗子: 如果一个链接显示为 Approve / Re ...