Solution to the problem that Java cannot connect to MySQL 8.0

Solution to the problem that Java cannot connect to MySQL 8.0

This article shares a collection of Java problems that cannot connect to MySQL 8.0 for your reference. The specific content is as follows

Question 1: Client does not support authentication protocol requested by Server;…

Question 2: Unknown initial character set index '255' received from server…

Question 3: MySQL 8.0 connection necessary URL statement

Problem 4: Duplicate method calls

Run Question 1 :

Solution: (note the semicolon in the 3 sentences, wy123456 is the password of my database)

Question 2:

Solution: (delete duplicate packages)

The import is also deleted, leaving only the correct one:

Then重啟eclipse! The environment will be updated~

Key: MySQL 8.0 needs to add this sentence : ?useSSL=false&serverTimezone=UTC

public static String dbUrl="jdbc:mysql://localhost:3306/websql?useSSL=false&serverTimezone=UTC"; 

Running results:

Question 4:

Solution: (The second connection name must be different)

Running results:

Attach the connection DbUtil class:

package com.cungudafa;

import java.sql.Connection;
import java.sql.DriverManager;

public class DbUtil {
  public static String dbUrl="jdbc:mysql://localhost:3306/websql?useSSL=false&serverTimezone=UTC";
  public static String dbUserName="root";
  public static String dbPassword="wy123456";
  public static String jdbcName="com.mysql.jdbc.Driver";

  public static Connection getCon() throws Exception {
   Class.forName(jdbcName);
   Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
    return con;
  }
  public static void closeCon(Connection con) {
    try {
      if (con != null) {
        con.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Java connects to mysql database code example program
  • Detailed explanation of the underlying encapsulation of Java connection to MySQL
  • Detailed explanation of how to connect Java to Mysql version 8.0.18
  • Java connects to MySQL database to implement single and batch insertion
  • Implementing a student management system based on MySQL in Java
  • Java+MySQL to implement student information management system source code
  • Detailed explanation of dynamically generating Mysql stored procedures in Java Spring

<<:  How to expand the disk partition for centos system

>>:  vue_drf implements SMS verification code

Recommend

Detailed explanation of nginx shared memory mechanism

Nginx's shared memory is one of the main reas...

A brief discussion on two current limiting methods in Nginx

The load is generally estimated during system des...

Detailed explanation of encoding issues during MySQL command line operations

1. Check the MySQL database encoding mysql -u use...

JavaScript function call classic example code

Table of contents JavaScript function call classi...

JavaScript to implement a simple web calculator

background Since I was assigned to a new project ...

JavaScript to achieve a simple page countdown

This article example shares the specific code of ...

Various methods to restart Mysql under CentOS (recommended)

1. MySQL installed via rpm package service mysqld...

Detailed explanation of MySQL date addition and subtraction functions

1. addtime() Add the specified number of seconds ...

MySql login password forgotten and password forgotten solution

Method 1: MySQL provides a command line parameter...

Nginx reverse proxy forwards port 80 requests to 8080

Let's first understand a wave of concepts, wh...

Use of align-content in flex layout line break space

1. The effect diagram implemented in this article...

MySQL master-slave replication principle and practice detailed explanation

Table of contents Introduction effect principle f...

The front-end page pop-up mask prohibits page scrolling

A problem that front-end developers often encount...