当前位置:网站首页>[JDBC] error exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communica
[JDBC] error exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communica
2022-07-24 04:28:00 【Lazy sheep.java】
SQL No problem with the writing ,JDBC Of jar The package is also imported normally , The following error is reported during operation because the database version is different from jar Package version is inconsistent

It used to be 5.1.47 Version of jar package , And the database is MySQL8.0.11 The version difference is too large to drive the connection
Import the new version jar After the package is added to the library, you can connect to the database normally

After successfully connecting to the database, some people may appear such a warning
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.
translate : Loading class com.mysql.jdbc. The driver '. This is not recommended . The new driver class is com.mysql.cj.jdbc. The driver . The driver passes SPI Automatic registration , There is usually no need to manually load driver classes .

Don't worry. ! I'll teach you how to solve it
First of all, this is a warning , It has no impact on the operation of the program You can see that the exit code is 0, This indicates that the program was successfully executed , But some friends have OCD and don't want to see what to do every time they run ?
Then just press the prompt to update the driver
Class.forName("com.mysql.cj.jdbc.Driver");Connection template :
public static void main(String[] args) throws SQLException, ClassNotFoundException {
//1. Registration drive
Driver driver = new Driver();
//2. Get links
String url = "jdbc:mysql://localhost:3306/pyq";
// Put the user name and password into Properties object
Properties properties=new Properties();
properties.setProperty("user","root");
properties.setProperty("password","284650"); // Your own password
Connection connect = driver.connect(url, properties);
//3. perform SQL
String sql="insert into actor values(null,' peng ',' male ','2000-5-20','220')";
Statement statement = connect.createStatement();
int rows = statement.executeUpdate(sql);
//4. Close the connection
statement.close();
connect.close();
}边栏推荐
- Chery arizer 8 products are powerful, and "all excellent" is not for nothing
- [translation] chaos mesh moved to CNCF incubator
- Collection of test case design methods
- 在一线城市上班的程序员,家庭一般是怎样的?
- 佳的性能和可靠性发起写入IIC协类型码和的参数是-4
- Combinatorial number (number of prime factors of factorials, calculation of combinatorial number)
- (5) Digital electricity formula simplification method
- IPhone binding 163 mailbox solution
- NFT除了买卖还能质押?
- 工程师能力模型与技能要求
猜你喜欢

Basic learning notes of C language

(5) Digital electricity formula simplification method

一次 svchost.exe 进程占用大量网络带宽的排查

Chery arizer 8 products are powerful, and "all excellent" is not for nothing

Iqoo 10 series attacks originos original system to enhance mobile phone experience

(零八)Flask有手就行——数据库迁移Flask-Migrate

Educational Codeforces Round 132 A - D

C语言经典习题之猴子吃桃问题

Page Jump and redirection in flask framework

PMIX ERROR: ERROR in file gds_ds12_lock_pthread.c
随机推荐
[untitled]
[C language] program environment and preprocessing operation
"PostgreSQL guide -- inside exploration" Chapter 2 process and memory architecture
Shell语法(二)
How long has it been since you changed your cell phone?
Robustness evaluation of commercial in vivo detection platform
.gz的业务交互和对外服篇中我们通合多个模型
C语言经典习题之编写一个程序,找出1000以内所有的完数。
MOS cameraization and digitization "includes designation (contro. skilled
一次 svchost.exe 进程占用大量网络带宽的排查
Live broadcast preview | practice sharing of opengauss' autonomous operation and maintenance platform dbmind
The problem of monkeys eating peaches in classic exercises of C language
Analyze the real-time development method of Bank of London
(5) Digital electricity formula simplification method
MOS摄像化、数字化”包含指定(contro.熟练的
Codeforces Round #808 (Div. 2) A - D
Smart contract: release an erc20 token
buu web
别人发的word中的参考文献是{}这样的乱码格式怎么办
Engineer competency model and skill requirements