The ultimate solution to use Eclipse to run Java code to read and write Chinese MySQL JDBC calls become a question mark

In the past two days debugging www.cnblogs.com/ericsun/archive/2011/11/25/2263062.html

But in the most simple to read and write Chinese MySQL when there is a problem, as before encountered when debugging J2EE applications.

Symptoms are: Java code calls JDBC MySQL database to read and write, I carefully checked the MySQL settings

I confirmed:

charset 1. Table I are set to become utf8 collation setting I became utf8_general_ci (with this online option to reinstall mysql character set, modify the method of the same principle my.ini)

2. Each table will use Chinese charset and collation of the column is also consistent with the 1

JDBC 3.Java end of the statement I have connected using jdbc: mysql: //127.0.0.1:? 3306 / student useUnicode = true & characterEncoding = UTF-8

4. Database Query result reading ResultSet when I have re-encoding method by a string of getBytes

So basically all the online methods are tried again, but no one is feasible, it's still a bunch of question marks.

 

That's when I thought of a thing, I was using Eclipse for development, the Eclipse project is to support custom character sets, so I modified the character set of project (select properties on the item -> Resource-> Text file encoding is selected other-> UTF-8), and then run the code again, this time just fine. Sahua celebrate!

Reproduced in: https: //www.cnblogs.com/ericsun/archive/2011/11/29/2267542.html

Guess you like

Origin blog.csdn.net/weixin_34357962/article/details/94155842