jsp+mysql中文转换问题-----------------------急求 连接数据库的charset设置成gb2312 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ......str=new String(str.getBytes("ISO8859-1"),"gb2312");......把上面那句话改成下面这句试试str=new String(str.getBytes("gb2312"),"iso-8859-1"); 存入数据库时用: 把数据转成8859_1的格式 name=new String(name.getBytes("gb2312"),"8859_1"); content=new String(content.getBytes("gb2312"),"8859_1"); insert into (name,content)values(?,?)....... 从数据库取的时候用: Connection con = DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1"); 从数据库取的时候指定编码方式为“8859_1”, 然后显示的时候进行转换: name=new String(name.getBytes("8859_1"),"gb2312"); 这种方法在MYSQL上通用 public static String toGBK(String str) { if (str == null) { return null; } try { return new String(str.getBytes("ISO8859_1"), "GBK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1"); //把useUnicode改为false,就好了。其它地方不用改 public class Chinese { public String getchinese(String str) { try { str=new String(str.getBytes("ISO8859-1"),"GBK"); } catch(Exception e) { e.printStackTrace(); } return str; }这样就OK了; 好象与web服务器也有关系~~用tomcat应该没问题的,用resin的话如果你是在jsp页面上这样做的话就会乱码,放到servlet里也应该没问题 我换了mssql,access都是这个问题是jdbc吗还是tomcat 存入数据库时用: 把数据转成8859_1的格式 name=new String(name.getBytes("gb2312"),"8859_1"); content=new String(content.getBytes("gb2312"),"8859_1"); insert into (name,content)values(?,?)....... 从数据库取的时候用: Connection con = DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1"); 从数据库取的时候指定编码方式为“8859_1”, 然后显示的时候进行转换: name=new String(name.getBytes("8859_1"),"gb2312"); 这种方法在MYSQL上通用 如果是resin的话就更好办了!只要在jsp页面上加入下面的就可以了!<%@ page contentType="text/html; charset=gb2312"%> 怪异的weblogic问题,紧急! 求助 response.sendredirect();问题 在线等 弱问:JSTL EL表达式 怎样调用方法? 关于站内搜索的一个问题 请教smartUpload高手 拜求各位 怎样把jsp的String数组赋值给javascript数组 【惊爆】微软最新惊人发现——胡万进事件『经过验证』 帮我试试这个返回值|? JSP在JBuilder8中!高手们帮忙!问题很简单!答对者分也! 菜鸟求助!!谢谢! 菜鸟想变高手:关于数据库连接!请高手一定提携!
str=new String(str.getBytes("ISO8859-1"),"gb2312");
......
把上面那句话改成下面这句试试
str=new String(str.getBytes("gb2312"),"iso-8859-1");
把数据转成8859_1的格式
name=new String(name.getBytes("gb2312"),"8859_1");
content=new String(content.getBytes("gb2312"),"8859_1");
insert into (name,content)values(?,?).......
从数据库取的时候用:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1");
从数据库取的时候指定编码方式为“8859_1”,
然后显示的时候进行转换:
name=new String(name.getBytes("8859_1"),"gb2312");
这种方法在MYSQL上通用
if (str == null) {
return null;
}
try {
return new String(str.getBytes("ISO8859_1"), "GBK");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
public String getchinese(String str)
{
try
{
str=new String(str.getBytes("ISO8859-1"),"GBK");
}
catch(Exception e)
{
e.printStackTrace();
}
return str;
}这样就OK了;
是jdbc吗
还是tomcat
把数据转成8859_1的格式
name=new String(name.getBytes("gb2312"),"8859_1");
content=new String(content.getBytes("gb2312"),"8859_1");
insert into (name,content)values(?,?).......
从数据库取的时候用:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1");
从数据库取的时候指定编码方式为“8859_1”,
然后显示的时候进行转换:
name=new String(name.getBytes("8859_1"),"gb2312");
这种方法在MYSQL上通用 如果是resin的话就更好办了!
只要在jsp页面上加入下面的就可以了!
<%@ page contentType="text/html; charset=gb2312"%>