插入数据后,数据库里的数据出现乱码?(急,在线等)

lily4064 2004-09-14 04:48:47

我用JSP+mysql开发的一个程序,在实现插入数据时,插入到数据库里的数据变成了乱码?这是怎么回事。
请高手们指点一下。
...全文
126 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lily4064 2004-09-14
  • 打赏
  • 举报
回复
就用jbas的方法,其实我上次也用过这样的,可是不行,刚才又行了。真搞不懂了。哎,无奈。
lily4064 2004-09-14
  • 打赏
  • 举报
回复
呵呵,搞定了。谢谢大家。
lily4064 2004-09-14
  • 打赏
  • 举报
回复
To:星河,仗剑走天崖
你们两个人说的方法,我都用过了,还是不行,是乱码。
jbas 2004-09-14
  • 打赏
  • 举报
回复
每个jsp页面开始加
<%@ page contentType="text/html; charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
orant 2004-09-14
  • 打赏
  • 举报
回复
public class ConverterEn {
public String convertEn_ch(String enString) throws Exception{
try{
String chString=new String(enString.getBytes("ISO-8859-1"));
return chString;
}
catch(Exception e){
System.out.println(e.toString());
}
return null;
}
}
gjd111686 2004-09-14
  • 打赏
  • 举报
回复
一般的只要保持客户端[JSP在这里是]与服务器[数据库]字符集一致就没有问题.
也可以
public String outStr(String strValue)
{
try
{
String strBuffer=strValue;
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
return strReturn;
}
catch(Exception e)
{
return null;
}
}
weepp 2004-09-14
  • 打赏
  • 举报
回复
上为正解!!!
schee 2004-09-14
  • 打赏
  • 举报
回复
在插入中文前需要转码,给你段代码,你可以参考一下:
public static String tochinese(String s)
{
try
{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(Exception e)
{
return s;
}
}
alaal 2004-09-14
  • 打赏
  • 举报
回复
将插入字段做转码
String aa=new String(aa.getBytes("ISO-8859-1"),"GB2312");
my2004good 2004-09-14
  • 打赏
  • 举报
回复
这是JSP的汉字问题,你到网上去搜一下,你会学到很多解决方法的。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧