mysql-connector-java.jar乱码,最新版mysql-connector-java-8.0.15.jar,如何愉快的进行JDBC操作...

注册驱动 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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值