博客
关于我
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 同一个列中的内容进行批量改动
查看>>
MySQL 命令和内置函数
查看>>
MySQL 和 PostgreSQL,我到底选择哪个?
查看>>
mysql 四种存储引擎
查看>>
mysql 在windons下的备份命令
查看>>
MySQL 在并发场景下的问题及解决思路
查看>>
MySQL 在控制台插入数据时,中文乱码问题的解决
查看>>
mysql 基础教程 一
查看>>
MySQL 基础架构
查看>>
MySQL 基础模块的面试题总结
查看>>
MySQL 处理插入重主键唯一键重复值办法
查看>>
Mysql 备份
查看>>
MySQL 备份 Xtrabackup
查看>>
mysql 复杂查询_mysql中复杂查询
查看>>
mYSQL 外键约束
查看>>
mysql 多个表关联查询查询时间长的问题
查看>>
mySQL 多个表求多个count
查看>>
mysql 多字段删除重复数据,保留最小id数据
查看>>
MySQL 多表联合查询:UNION 和 JOIN 分析
查看>>
MySQL 大数据量快速插入方法和语句优化
查看>>