The coding problem between Java and MySQL

Source: Internet
Author: User

I have not been the first to configure the database so I have not found this problem, Baidu found on the network and there is no corresponding solution, so I began to explore their own solution to the problem.

The problem is roughly the same, there is a table in the database, and when I delete the Ganso in the table in the Java code, there is no way to remove the Chong from the Chinese attribute value. may not be very accurate, and then I will cooperate with the picture to explain it.

Tools/Materials
    • Mysql
    • Eclipse
    • Navicat
Method/Step
    1. In general, this problem is due to the fact that the database and the compilation environment use a different encoding, in order to facilitate the explanation I give a student information table for example.

      For example, there is now a student named Xiao Ming (char type), the corresponding study number is 1 (INR type), according to the number of students to delete the number 1 Xiao Ming executive results without any problems, according to the name of the deletion of the name of Xiao Ming can not be deleted. If you have the same problems as I do then look down, if not that may not help you in the following content.

    2. First, check the text encoding of the current database.

      SHOW VARIABLES like ' character_set_% '

    3. I am using the MySQL database, the code is as follows:
    4. The workaround is simple to add a sentence after the database connection statement? USEUNICODE=TRUE&CHARACTERENCODING=GBK on the line.

      String url = "Jdbc:mysql://localhost:3306/db_databaseuseunicode=true&characterencoding=gbk"; String user = "root"; String PassWord = "root";

The coding problem between Java and MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.