JSP connection mysql and display Chinese normally

xiaoxiao2021-03-05  21

Recently, I didn't work, I learned a bit of JSP. I drums for a long time, I finally got Mysql, but I found that Chinese searched from MySQL didn't show it. All fucking is ???. Search for MY

Unicode is not supported in SQL only support ISO-88591, so the genius I came up with the solution :) Turn the search string into the array array, then create a GB2312 string with this character array. <% = NEW STRING (rs.getstring (2) .Getbytes ("ISO8859-1"), "GB2312")%> Anyway, I am very simple. I also explain it. There is all of the code below. Possible people don't know how to connect with JSP connections Database. Where people are the name of the database root is the username 000000 is the password. You need a MySQL JDBC driver. I use: mysql-connector-java-3.0.15-ga-bin.jar online can be found, only need Download this file down in your directory in your JSP file / Web-INF / LIB can be. ======================== = TestMysql.jsp =============================================================================================================================================

<% @ Page ContentType = "Text / HTML; Charset = GBK"%> <% @ page language = "java" import = "java.sql. *"%> <% java.sql.connection conn; java.lang. String strconn; class.forname ("org.gjt.mm.mysql.driver); conn = java.sql.driverManager.getConnection (" JDBC: MySQL: /// people "," root "," 000000 "); Statement Stmt = Conn.createStatement (); ResultSet RS = Stmt.executeQuery ("SELECT * FROM T_1");%> <% for (INT i = 0; rs.next (); i ) {%> <% = new String (rs.getstring (2) .GetBytes ("ISO8859-1"), "GB2312")%>
<%}%>

==================================================================================================================================================================================== ==========

# ------------------------------------------------- -------

## Table structure `T_1` #

Create Table `T_1` (` ID` int (4) Not null default '0', `Name` Char (20) Not null default ',` Phone` int (20) Default Null, Primary Key (`ID`) ) Type = myisam; ## Export data in the table` T_1` #

INSERT INTO `T_1` Values ​​(1, 'I am not', 2147483647); INSERT INTO` T_1` Values ​​(2, 'Pig', 2147483647)

============================================================================================================================================================================================================= ==================== OK, write it .... understanding people look very simple,

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

New Post(0)