Hibernate connection database coding error problem

Hibernate connection database coding error problem

error problem

Recently, I was learning hibernate, and after watching some videos, I imitated and wrote some codes, but there were always errors when running, as shown in the following figure:
insert image description here

problem discovery

Look carefully at the output information, scroll down, and I saw this:
insert image description here
I googled it, this is a problem of encoding mismatch, the article written by this blogger, https://blog.csdn.net/txwtech/article/ details/80787886
you can take a look

In order to make sure that my problem must be an encoding mismatch, I wrote a .java program and used jdbc to connect to mysql. Sure enough, I didn’t add such a long string of codes later, and I couldn’t connect to the database. The character set change code above seems a bit The problem, I can’t run it, the following is mine, the operation is successfully connected to the database

jdbc:mysql://127.0.0.1:3306/database name?useUnicode=true&characterEncoding=utf-8

So, I can be sure that the problem is indeed caused by the mismatch between the driver package and the database encoding.

problem solved

Added after the driver in hibernate.cfg.xml, but an error occurred. It is impossible to delete the jdbc driver of mysql. After all, I don't know which version can be used after deleting it.

After working on it for a long time, I suddenly remembered that my mysql encoding does not seem to be utf-8. Mysql was just installed two days ago. The my.ini file was written by myself. I simply changed it to utf8mb4:
insert image description here

final solution

Change the encoding in my.ini back to utf8, restart the mysql service, run it again, and the error disappears

insert image description hereinsert image description here

Guess you like

Origin blog.csdn.net/wangzhiyu12/article/details/90477226