Home Java JavaBase Solution to Chinese garbled characters when java adds data to mysql

Solution to Chinese garbled characters when java adds data to mysql

Nov 12, 2019 pm 01:20 PM
java mysql Chinese garbled Solution

Solution to Chinese garbled characters when java adds data to mysql

Cause:

The reason for garbled characters is inconsistent character sets. Usually, you only need the character set specified when creating the database table and the java database setting The character set specified by the connection setting URL is consistent.

Solution:

1. When creating the database:

     CREATE   DATABASE   `Db` 
      CHARACTER   SET   'utf8 ' 
      COLLATE   'utf8_general_ci ';
Copy after login

2. When creating the table:

 CREATE   TABLE   `TableA`   ( 
      `ID`   varchar(40)   NOT   NULL   default   ' ', 
        `UserID`   varchar(40)   NOT   NULL   default   ' ',  ) 
                  ENGINE=InnoDB   DEFAULT   CHARSET=utf8;
Copy after login

3. When setting the database url in java:

jdbc:mysql://localhost:3306/store_40?useUnicode=true&characterEncoding=utf-8
Copy after login

Recommended tutorial: Java tutorial

The above is the detailed content of Solution to Chinese garbled characters when java adds data to mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that custom structure labels in Goland do not take effect? How to solve the problem that custom structure labels in Goland do not take effect? Apr 02, 2025 pm 12:51 PM

Regarding the problem of custom structure tags in Goland When using Goland for Go language development, you often encounter some configuration problems. One of them is...

How to solve the problem of Golang generic function type constraints being automatically deleted in VSCode? How to solve the problem of Golang generic function type constraints being automatically deleted in VSCode? Apr 02, 2025 pm 02:15 PM

Automatic deletion of Golang generic function type constraints in VSCode Users may encounter a strange problem when writing Golang code using VSCode. when...

How to specify the database associated with the model in Beego ORM? How to specify the database associated with the model in Beego ORM? Apr 02, 2025 pm 03:54 PM

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

Common errors and ways to avoid char in C language Common errors and ways to avoid char in C language Apr 03, 2025 pm 03:06 PM

Errors and avoidance methods for using char in C language: Uninitialized char variables: Initialize using constants or string literals. Out of character range: Compare whether the variable value is within the valid range (-128 to 127). Character comparison is case-insensitive: Use toupper() or tolower() to convert character case. '\0' is not added when referencing a character array with char*: use strlen() or manually add '\0' to mark the end of the array. Ignore the array size when using char arrays: explicitly specify the array size or use sizeof() to determine the length. No null pointer is not checked when using char pointer: Check whether the pointer is NULL before use. Use char pointer to point to non-character data

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

How to choose the solution for data consistency between MySQL and Redis: the difference between delayed double deletion and first modifying the database and then deleting the cache and applicable scenarios? How to choose the solution for data consistency between MySQL and Redis: the difference between delayed double deletion and first modifying the database and then deleting the cache and applicable scenarios? Apr 02, 2025 am 11:57 AM

Two solutions for data consistency between MySQL and Redis: delayed double deletion and first modifying the database and then deleting cache are used to handle data consistency problems in MySQL and Redis, ...

What is NULL useful in C language What is NULL useful in C language Apr 03, 2025 pm 12:03 PM

NULL is a special value in C language, representing a null pointer, which is used to identify that the pointer variable does not point to a valid memory address. Understanding NULL is crucial because it helps avoid program crashes and ensures code robustness. Common usages include parameter checking, memory allocation, and optional parameters for function design. When using NULL, you should be careful to avoid errors such as dangling pointers and forgetting to check NULL, and take efficient NULL checks and clear naming to optimize code performance and readability.

Loop and pointer problem in Go language: Why are v.name 'blogs'? Loop and pointer problem in Go language: Why are v.name 'blogs'? Apr 02, 2025 pm 12:48 PM

Loop and pointer problem in Go language: Why are v.name "blogs"? In Go programming, sometimes you will encounter some seemingly strange problems,...

See all articles