Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What about the garbled codes in mysql jdbc?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail what to do about mysql jdbc Chinese garbled code. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The solution to Chinese garbled code in mysql jdbc is to explicitly set the characterEncoding property to utf8 in jdbc url, such as "jdbc:mysql://host:port/dbname?characterEncoding=utf8".

This article operating environment: Windows7 system, Mysql5.7 version, Dell G3 computer.

Solution of garbled code in writing Chinese by jdbc mysql

one。 problem

Database code: utf8

Mysql > create database dbnameDEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Table coding: utf8

Drop table if exists `test`; create table `test` (`id` bigint (20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar (50) default', `create_ time`creation time', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8

Jdbc url:

Url: jdbc:mysql://host:port/dbname

The database and database tables have been encoded with utf8, but they are still garbled when inserting Chinese data.

two。 Reason

When connecting to mysql in jdbc, there is an attribute characterEncoding in the jdbc url parameter that controls string encoding, which defaults to: autodetect. It needs to be explicitly set to utf8 to solve the problem.

The MySQL documentation is explained below, as detailed in the "Setting Configuration Properties" section of https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html.

three。 Solution.

Explicitly set the characterEncoding property to utf8 in jdbc url.

Url: this is the end of jdbc:mysql://host:port/dbname?characterEncoding=utf8 's article on "what to do about Chinese garbled code in mysql jdbc". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report