First, clarify a few concepts:
JDBC operation steps: (1) Create a database and table (2) Create a project (3) Import the driver jar package (4) Register the driver (5) Get a connection Preface I recently installed a MySQL 8.0 database, and there were constant problems when connecting to it in the program. I have encountered some problems before. Here is a summary of the problems that may occur when using JDBC to connect to MySQL. Before that, let me explain the environment:
Driver package URL changes Exception information
reason Through the exception, we can find that the new driver url is com.mysql.cj.jdbc.Driver. After consulting the information online, we found that starting from MySQL 6, the driver package began to use the new driver url. If you use the old 5.0 version of the driver package, you do not need to use the driver URL, but some unexpected problems may occur if you use the old driver. Therefore, it is recommended to upgrade the driver package and then change the value of the driver URL. Workaround Change the driver URL from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver SSL Warning Warning Message
reason The warning message is translated as follows.
Workaround Generally, you don't need to use SSL connection in development. Just add the useSSL=false parameter after the connection string. But if you really need an SSL connection, add the useSSL=true parameter after the driver URL. jdbc:mysql://localhost:3306/dbname?characterEncoding=UTF-8&useSSL=false Time zone issues Exception information
reason Also, after the version upgrade, there is a time zone difference between the new version database and the system, so the time zone serverTimezone needs to be specified Workaround Add the parameter &serverTimezone=GMT%2B8 after the connection string. The final connection string is as follows: jdbc:mysql://localhost:3306/dbname?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8 Modify the database time. First connect to the database through the command line, enter the commands and their outputs in sequence as follows mysql> show variables like "%time_zone"; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | | | time_zone | SYSTEM | +------------------+--------+ 2 rows in set, 1 warning (0.04 sec) mysql> set global time_zone="+8:00"; Query OK, 0 rows affected (0.01 sec) Escaping & in XML configuration files Exception information
reason This is the error I get when using mybatis generator. At that time, I wanted to add the useSSL parameter after the connection string, but since & is prohibited in XML files, when & is needed, it must be replaced with its escape symbol &. Workaround Change the & symbol in the connection string to & Detailed connection string reference jdbc:mysql://127.0.0.1:3306/dbname?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&serverTimezone=GMT%2B8&verifyServerCertificate=false&autoReconnct=true&autoReconnectForPools=true&allowMultiQueries=true Of course, if you use XML as the configuration file, you need to change the & symbol in the connection string to & Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Complete steps for Docker to pull images
>>: Complete steps for vue dynamic binding icons
How to set a limit on the number of visits to a c...
1. Install MySQL database ① Download and unzip an...
SQL implements addition, subtraction, multiplicat...
In order to centrally manage the images we create...
How to use css variables in JS Use the :export ke...
Binlog is a binary log file that is used to recor...
1. Video tag Supports automatic playback in Firef...
Recently, after refreshing the website, 503 Servi...
[LeetCode] 176. Second Highest Salary Write a SQL...
Table of contents Preface 1. MySQL main storage e...
Static files Nginx is known for its high performa...
Copy code The code is as follows: .sugLayerDiv{ p...
1. Time formatting and other methods It is recomm...
1. readonly read-only attribute, so you can get th...
Preface Before we start explaining the principle ...