Prepared Statement Chinese garbled solution in mysql

Source: Internet
Author: User


During the top Shard, The PreparedStatement encountered garbled Characters During database storage, which had plagued the database for a long time and finally solved the problem.
The problem code is as follows: [java] pstmt = con. prepareStatement (INSERT_OFFLINE); pstmt. setString (1, username); pstmt. setLong (2, messageID); pstmt. setString (3, StringUtils. dateToMillis (new java. util. date (); pstmt. setInt (4, msgXML. length (); pstmt. setString (5, "Chinese content"); pstmt.exe cuteUpdate (); www.2cto.com during debugging, the "Chinese content" in pstmt.exe cuteUpdate (); line pstmt is changed ???? The reason is that jdbc is used to set the datasource driver. url = jdbc: mysql: // 192.168.12.22: 3306/ts does not specify the encoding. You can modify jdbc as follows. url = jdbc: mysql: // 192.168.12.22: 3306/ts? CharacterEncoding = utf8 Problem Solving author a352193394

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.