博客
关于我
mysql-connector-java.jar乱码,最新版mysql-connector-java-8.0.15.jar,如何愉快的进行JDBC操作...
阅读量:795 次
发布时间:2023-02-11

本文共 2502 字,大约阅读时间需要 8 分钟。

注册驱动 com.mysql.cj.jdbc.DriverLoading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

数据库的连接对象Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false","root","password");数据库的时区和我本地的时区不一样 ==> serverTimezone=UTC(com.mysql.cj.jdbc.Driver时需要额外增加一个时区的参数)SQLException: 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.

SQLState: 01S00

VendorError: 0

如果输入中文存在乱码characterEncoding=UTF-8

useSSL=false 连接配置详解:原因是MySQL在高版本需要指明是否进行SSL连接。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.

SSL协议提供服务主要:

1)认证用户服务器,确保数据发送到正确的服务器;    .

2)加密数据,防止数据传输途中被窃取使用;

3)维护数据完整性,验证数据在传输过程中是否丢失;

当前支持SSL协议两层:

SSL记录协议(SSL Record Protocol):建立靠传输协议(TCP)高层协议提供数据封装、压缩、加密等基本功能支持

SSL握手协议(SSL Handshake Protocol):建立SSL记录协议用于实际数据传输始前通讯双进行身份认证、协商加密算法、 交换加密密钥等。是否使用Unicode字符集useUnicode 是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为true

标准连接JDBC/*

JDBC快速入门

*/

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class jdbcDemo1 {

public static void main(String[] args) throws ClassNotFoundException, SQLException {

//1.导入驱动jar包

//2.注册驱动

Class.forName("com.mysql.cj.jdbc.Driver");

//3.获取数据库的连接对象

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false","root","password");

//4.定义sql的对象Statement

String sql = "update salary set mony =500 where id = 1 ";

//5.获取执行sql的对象Statement

Statement stmt = conn.createStatement();

//6.执行sql

int count = stmt.executeUpdate(sql);

//7.处理结果

System.out.println(count);

//8.释放资源

stmt.close();

conn.close();

}

}

转载地址:http://icbfk.baihongyu.com/

你可能感兴趣的文章
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
mui折叠面板点击事件跳转
查看>>
MySQL 8 公用表表达式(CTE)—— WITH关键字深入用法
查看>>
mysql 8 远程方位_mysql 8 远程连接注意事项
查看>>
MUI框架里的ajax的三种方法
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
Mysql 8.0 新特性
查看>>
MultCloud – 支持数据互传的网盘管理
查看>>
MySQL 8.0.23中复制架构从节点自动故障转移
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>