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
Table of contents Preface Modifiers of v-model: l...
1. What is Refs is called Resilient File System (...
There are many database management tools for MySQ...
Introduction MySQL slow query log is an important...
I have been having this problem recently when desi...
Purpose: Allow the state data managed in vuex to ...
When the height attribute of Text is defined, the ...
The cursor size in the input box is inconsistent T...
During my internship in my senior year, I encount...
Here is the mysql driver mysql.data.dll Notice: T...
This article example shares the specific code of ...
Table of contents 1. Environment 2. Preparation 3...
In the process of writing HTML, we often define mu...
Generate a certificate chain Use the script to ge...
Rendering pipeline with external css files In the...