转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> MySql >> 正文
Mysql5.0中文乱码解决方案         ★★★★

Mysql5.0中文乱码解决方案

作者:闵涛 文章来源:闵涛的学习笔记 点击数:676 更新时间:2009/4/22 20:48:39
最近学到jsp连接数据库那一块的时候,我也遇到了中文乱码问题~~呵呵,很头疼哦!
   我用的数据库是Mysql5.0,所以,我先用google,baidu等上网搜了一下解决方案,自己也按着方法反复测试了一、两天之后,终于解决了我的JSP+Mysql5.0+tomcat-5.0.29出现的乱码问题。
   解决方案如下:
   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>

好了,现在让你头疼的mysql中文乱码问题是不是已经迎刃而解了呢?~~呵呵,搞定!


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台