MySQL5.0 Chinese problem and JDBC database connection and JSP encoding problem solving method Summary

Source: Internet
Author: User
Tags character set copy file copy html page insert mysql variables create database
js|mysql| Code | Chinese Character | solve | data | database | database Connection | problem |

There are many ways to solve this problem, today in this simple end, the often encountered problem-solving method down!

1, the MySQL5.0 Chinese problem solution is as follows:

1, in the DOS environment, with MySQL--default-character-set=gbk-u root-p this sentence into the mysql~~

2, build database, table, as follows:

Create DATABASE admin;

Use admin;

CREATE TABLE Admin (

Admin_name char (not NULL),

Admin_password char (not NULL)

) Type=myisam,

Default character set GBK;

2, JDBC Setup problem: (this is mainly about mysql-connector-java- 3.1.8 this JDBC driver)

This is just a compressed package, do not need to install, as long as the decompression, using the folder mysql-connector-java- 3.1.8 files: Mysql-connector-java-3.1.8-bin.jar.

The JDBC driver is required to configure the environment variables. Before configuring the mysql-connector-java-3.1.8-bin.jar to put on the local hard drive somewhere (I put the place: E:\JAVA\MySQLJDBC), and then according to your place, configure classpath< /c2>, my configuration is this:

.; E:\Java\j2se5.0\lib\tools.jar; E:\Java\j2se5.0\lib\mysql-connector-java-3.1.8-bin-g.jar; E:\JAVA\MySQLJDBC\mysql-connector-java-3.1.8-bin.jar

The purpose of this configuration is to get your Java application to find the driver to connect to MySQL.

After configuring the environment variables there is a very important step is to the JSP connection database configuration driver, this is actually very simple, is the mysql-connector-java- 3.1.8- Bin.jar copy to some folders on the line, I read a lot of information on the Internet to ask a lot of people, all kinds of statements have, I synthesized a bit, in order to insure, I have all done, oh, anyway is a 400K file, is listed to the Mysql-connector-java-3.1.8-bin.jar Go to the folder, as follows:

E:\Java\Tomcat5.0\common\lib

E:\Java\Tomcat5.0\shared\lib

In general, as long as the test to Tomcat5.0 above the two problem folder can solve the problem, if necessary, you can also mysql-connector-java- 3.1.8-bin.jar This driver file copy to your WEB site ... \web-inf \lib directory below.

3, the Chinese encoding problem when manipulating databases in the database plug-in in eclipse:

When you load up your favorite database plugin in Eclipse, it appears that the characters in the records are garbled after you query a database. The solution is simple,

Just set the URL to the following when you set up a database connection:

Url= JDBC:MYSQL://LOCALHOST:3306/?USEUNICODE=TRUE&CHARACTERENCODING=GBK

4, in the JSP Web editor personal experience: after a lot of debugging, found in the installed MyEclipse, there is such a small:

When writing HTML files with MyEclipse CHARSET=GBK set this way, then browsing in the browser will not appear garbled;

While editing a JSP file with MyEclipse, <%@ page contentType= "text/html;charset=gb2312"%> set to this, And this statement must be the entire JSP file the first statement, you can avoid JSP files in the browser appears garbled;

If you want to receive data from an HTML page in a JSP page, the encoding of the receive statement in the JSP should be the same as the encoding of the HTML of the data source; The encoding of HTML in is CHARSET=GBK, then the receive statement in the JSP should be set like this: Request.setcharacterencoding ("GBK"), and if you want to insert the accepted data into the database ( To insert the MySQL5.0 database as an example, the encoding should also be the same as the encoding in the HTML file when inserting the database, and my settings are as follows: con= drivermanager.getconnection ("jdbc:mysql:// LOCALHOST:3306/SAMPLE_DB?USER=DAZERN&PASSWORD=5201314&USEUNICODE=TRUE&CHARACTERENCODING=GBK "); After this setting, the data in the database will not be garbled.

The above experience is in MyEclipse 3.8.3+tomcat5.0.28 test, no mistake! Here for reference only, the specific situation has to be specific analysis!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.