Mysql5.0中文乱码解决方案
生活随笔
收集整理的這篇文章主要介紹了
Mysql5.0中文乱码解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解決方案如下:
??? ?1、在dos環境下,用mysql --default-character-set=gbk -u root -p 這句話進入mysql~~
???? 2、建數據庫、表,如下:
??????? create database admin;
?????????? use admin;
?????????? CREATE TABLE admin (
?????????? admin_name char(20) NOT NULL,
?????????? admin_password char(20) NOT NULL
?????????? ) TYPE=MyISAM,
?????????? default character set gbk;??
???? 3、接著用如下testgbk.jsp測試,
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" import="java.io.*" %>
<%??
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");??
conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/admin?user=root&password=123456&useUnicode=true&characterEncoding=gbk");
Statement stmt=conn.createStatement();
ResultSet rs=null;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title></title>
</head>
<body>
<table width="314" height="34" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#6666FF">
??<tr>??
????<td align="center" height="19" width="100" style="font-size:10pt;color:red;">帳號</td>
????<td align="center" height="19" width="40" style="font-size:10pt;color:red;">密碼</td>
??</tr>??
<%??
String temp = "insert into admin(admin_name,admin_password) values('你們好','123')";
PreparedStatement pst = conn.prepareStatement(temp);
pst.executeUpdate();
pst.close();
//結束
temp = "select * from admin";
rs=stmt.executeQuery(temp);
while(rs.next()){
String admin=rs.getString("admin_name");
String pass=rs.getString("admin_password");
%>
??<tr>??
????<td align="center" height="19" width="100" style="font-size:10pt;color:blue;"><%=admin%></td>
????<td align="center" height="19" width="40" style="font-size:10pt;color:blue;"><%=pass%></td>
</tr>??
<%
}
%>
<%??
rs.close();
stmt.close();
conn.close();??
%>
??<tr>??
????<td height="19" colspan="4" align="center" style="font-size:10pt;color:red;"> </td>
??</tr>
</table>
</body>
</html>
??? ?1、在dos環境下,用mysql --default-character-set=gbk -u root -p 這句話進入mysql~~
???? 2、建數據庫、表,如下:
??????? create database admin;
?????????? use admin;
?????????? CREATE TABLE admin (
?????????? admin_name char(20) NOT NULL,
?????????? admin_password char(20) NOT NULL
?????????? ) TYPE=MyISAM,
?????????? default character set gbk;??
???? 3、接著用如下testgbk.jsp測試,
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" import="java.io.*" %>
<%??
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");??
conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/admin?user=root&password=123456&useUnicode=true&characterEncoding=gbk");
Statement stmt=conn.createStatement();
ResultSet rs=null;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title></title>
</head>
<body>
<table width="314" height="34" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#6666FF">
??<tr>??
????<td align="center" height="19" width="100" style="font-size:10pt;color:red;">帳號</td>
????<td align="center" height="19" width="40" style="font-size:10pt;color:red;">密碼</td>
??</tr>??
<%??
String temp = "insert into admin(admin_name,admin_password) values('你們好','123')";
PreparedStatement pst = conn.prepareStatement(temp);
pst.executeUpdate();
pst.close();
//結束
temp = "select * from admin";
rs=stmt.executeQuery(temp);
while(rs.next()){
String admin=rs.getString("admin_name");
String pass=rs.getString("admin_password");
%>
??<tr>??
????<td align="center" height="19" width="100" style="font-size:10pt;color:blue;"><%=admin%></td>
????<td align="center" height="19" width="40" style="font-size:10pt;color:blue;"><%=pass%></td>
</tr>??
<%
}
%>
<%??
rs.close();
stmt.close();
conn.close();??
%>
??<tr>??
????<td height="19" colspan="4" align="center" style="font-size:10pt;color:red;"> </td>
??</tr>
</table>
</body>
</html>
轉載于:https://blog.51cto.com/tscjsj/85908
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Mysql5.0中文乱码解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习编程需要攻克的8个难关,一旦没有把握
- 下一篇: 2005年度国产空间信息系统软件测评工作