Chinaunix首页 | 论坛 | 博客
  • 博客访问: 711413
  • 博文数量: 147
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1725
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-22 10:36
文章分类

全部博文(147)

文章存档

2011年(1)

2010年(1)

2009年(35)

2008年(110)

我的朋友

分类: Mysql/postgreSQL

2008-08-23 08:17:27

windows上的:

首先建表和jsp页面都要用gb2312编码,然后进入mysql的安装目录,找到my.ini文件,找到如下几行:
[mysql]
default-character-set=gb2312,将她改为gb312即可,同时我们可以看出此文件是mysql的配置文件,包括可以配置端口,数据库存放目录
和mysql的日志目录,所以掌握好这个配置文件mysql的一些基本问题能够解决。
下面给出一个插入数据库时候解决中文乱码的类:
public class Chinese {
public static String toChinese(String strvalue){
    try{
        if(strvalue==null){
            return "";
        }else{
            strvalue=new String(strvalue.getBytes("ISO8859_1"),"gb2312");
            return strvalue;
        }
    }catch(Exception e){
    return "";
    }
    
}
}
在linux下:

/etc/my.cnf字符编码是utf-8

package chinese;

public class Chinese {
public static String toChinese(String strvalue){
 try{
  if(strvalue==null){
   return "";
  }else{
   strvalue=new String(strvalue.getBytes("latin1"),"utf-8");
   return strvalue;
  }
 }catch(Exception e){
 return "";
 } 
}
}

阅读(820) | 评论(0) | 转发(0) |
0

上一篇:EJB QL

下一篇:单例类

给主人留下些什么吧!~~