日期:2014-05-18  浏览次数:20750 次

mysql数据库中文在jsp上显示为问号????
我用的版本5.0   安装时候选择的就是gb2312
查了网上的N多方法
my.ini的两个字符集设置,均设定为gb2312
private   String   dbUrl   =     "jdbc:mysql://localhost:3306/BookDB?useUnicode=true&characterEncoding=gb2312 ";
<%@page   contentType= "text/html;charset=GB2312 "   pageEncoding= "GB2312 "%>

结果在dos下是汉字,在jsp页面显示还是问号

望大家指点

------解决方案--------------------
引起mysql乱玛有好多。一种是显示乱码。一种是数据中乱码。
你用这个三个函数转一下看一下。

//乱玛转换
public static String ISO8859_1(String str)
{
try
{
if(str==null)
str = " ";
else
str=new String(str.getBytes( "ISO8859_1 "), "GBK ");
}catch (Exception e) {System.out.println( "DealString::toGBK(String)运行时出错:错误为: "+e);}
return str;
}


//乱玛转换

public static String toGBK(String str)
{
try
{
if(str==null)
str = " ";
else
str=new String(str.getBytes( "ISO-8859-1 "), "GBK ");
}catch (Exception e) {System.out.println( "DealString::toGBK(String)运行时出错:错误为: "+e);}
return str;
}
//乱玛转换
public static String toUTF8(String str)
{
try
{
if(str==null)
str = " ";
else
str=new String(str.getBytes( "UTF-8 "), "GBK ");
}catch (Exception e) {System.out.println( "DealString::toGBK(String)运行时出错:错误为: "+e);}
return str;
}