当前位置: 技术问答>java相关
jsp+mysql的中文显示问题
来源: 互联网 发布时间:2015-10-01
本文导语: 我们的网站是用jsp+mysql作的,但有关从数据库读出的数据都是????????????,请高手指教,我们的原程序是在美国写的,是不是和系统有关! | public static String UToC(String s){ ...
我们的网站是用jsp+mysql作的,但有关从数据库读出的数据都是????????????,请高手指教,我们的原程序是在美国写的,是不是和系统有关!
|
public static String UToC(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String CToU(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String CToU(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
|
JSP中
request.setCharacterEncoding("gb2312");
连接数据库的URL:
jdbc:mysql://yourServer/yourDatabase?useUnicode=true&characterEncoding=gb2312
request.setCharacterEncoding("gb2312");
连接数据库的URL:
jdbc:mysql://yourServer/yourDatabase?useUnicode=true&characterEncoding=gb2312
|
http://www.csdn.net/expert/topic/1065/1065682.xml?temp=.1146967
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。