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:
- Pstmt = con. prepareStatement (INSERT_OFFLINE );
- Pstmt. setString (1, Username );
- Pstmt. setLong (2, MessageID );
- Pstmt. setString (3, StringUtils. dateToMillis (NewJava. util. Date ()));
- Pstmt. setInt (4, MsgXML. length ());
- Pstmt. setString (5, "Chinese content ");
- Pstmt.exe cuteUpdate ();
During debugging, the "Chinese content" in pstmt.exe cuteUpdate (); line pstmt is changed ????
The cause is that jdbc. url = jdbc: mysql: // 192.168.12.22: 3306/ts does not specify the encoding when the datasource driver is set.
You can modify it as follows:
Jdbc. url = jdbc: mysql: // 192.168.12.22: 3306/ts? CharacterEncoding = utf8
Problem Solving