This paper explains the problems I have encountered
1. Through the JDBC Direct connection, connect Mysql database, from the program to write data to the database garbled solution.
When a program writes a piece of data to the Student table, the content written to the database is garbled.
Such as
Solution:
1. When creating a database:
CREATE DATABASE ' Db '
CHARACTER SET ' UTF8 '
COLLATE ' Utf8_general_ci ';
2. when the table is built :
CREATE TABLE ' TableA ' (
' ID ' varchar (+) not NULL default ' ',
' UserID ' varchar (+) not NULL default ', ')
Engine=innodb DEFAULT Charset=utf8;
But I feel the relationship is not very big, but can be used as a means of trying.
3. This program is effective, is to modify the Mysql installation directory configuration file
You need to modify the encoding for the two locations in the My.ini
First place
Second place:
After setting, restart the service via the command
Final problem resolution.
2. If it is garbled to read data from the MySQL database through jdbc , but the data in the database itself is not garbled, then you can use the URL The solution for adding parameters.
The URL is spelled as follows:
Jdbc:mysql://localhost:3306/database?useunicode=true&characterencoding=utf-8
3. If you replace localhost in the URL with an IP Address, the following issue occurs:
Error : 1130-host allowed to connect to this MYSQL server
Workaround:
1. Change the table method.
It may be that your account is not allowed to log on remotely, only on localhost. This time, as long as the computer on the localhost , log in to MySQL , the "MySQL" database to change the " " Host" item in User "table", renamed " %" from "localhost "
Mysql-u root-pvmwaremysql>use MySQL;
Mysql>update User Set host = '% ' where user = ' root ';
To refresh the authorization, the line code must have: FLUSH privileges;
4.jdbc-odbc Bridge Connection method reading data from the database garbled solution
Do not read directly, you can use the following ways to convert the read, problem solving
Stringstuname=new String (Rs.getbytes (2), "Utf-16le");
Conclusion:JDBC and database interaction garbled is often encountered in the development of difficult problems, I hope the summary here can help you.