JSP connection mysql garbled problem solved

xiaoxiao2021-03-06  40

JSP connection mysql database If there is a Chinese access, there is a garbled, and the Chinese shows a bunch of "?",

Need to do the following change

1. Connection string:

String mysqldriver = "org.gjt.mm.mysql.driver"; // Database driver

String mysqlurl = "JDBC: mysql: // localhost: 3306 / bbs? Useunicode = true & characterencoding = GB2312"; // Database connection string

String mysqluser = "root"; // Database Username

String mysqlpsw = ""; // database password

Class.Forname ("org.gjt.mm.mysql.driver"). NewInstance (); // Register Driver

Conn = drivermanager.getConnection (mysqlurl, mysqluser, mysqlpsw); // Get a connection

2. Request object settings:

<% Request.SetCharacterencoding ("GB2312");%>

Set the character set of the JSP's request object to support Chinese

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

New Post(0)