JSPjdbc mysql garbled problem ~~~

xiaoxiao2021-03-06  41

Green:

JSP's Request default is ISO8859_1, so when you are processing Chinese,

If you want to display Chinese, you must turn into GBK, as follows

String str = new string (Request.GetParameter ("name"). GetBytes ("ISO8859-1"), "GBK");

Out.println (STR);

This will display Chinese.

PS: A very important thing is the driver of JDBC: My current is mysql-connector-java-3.0.10-stable-bin.jar. .

Chinese issues in mysql operation:

This depends on the default encoding of mysql. If it is generally not adjusted, Latin1 is actually the same as ISO8859_1, so it is necessary to deal with him when the operation is handled, otherwise it will be garbled.

1. Insert Chinese:

String SQL2 = "INSERT INTO TEST (NAME) VALUES ('" Request.getParameter ("Name") "" "

Stmt.executeUpdate (SQL2);

You can insert it without coding.

2. Show inserted Chinese:

Because the deposit is Latin, it will be GBK when it is displayed.

String x = new string ((rs.getstring ("title")). Gettes ("ISO8859_1"), "GBK");

Out.println (x);

3. Set the storage code:

Of course, when Mysql is Latin1 encoding, you can use GBK when you save.

Connection Con = DriverManager.getConnection ("JDBC: MySQL: / / LocalHost: 3306 / JSP? Useunicode = true & characterencoding = GBK", "root", "");

STR1 = "Chinese";

String SQL2 = "INSERT INTO TEST (NAME) VALUES ('" str1 ")";

This can also be inserted successfully, huh, huh

PS: Old is to forget this ~~~ Be a marker

转载请注明原文地址:https://www.9cbs.com/read-60678.html

New Post(0)