关于mysql插入问题和乱码

huangwenyou9 2008-03-04 12:24:08
我在应用中,不能插入,只能查询但查询出来中文乱码



我的问题大致如下

其中数据库 设置为utf-8.

连接语句为
private String url = "jdbc:mysql://localhost:3306/db_shopping?useUnicode=true&characterEncoding=utf-8";
和connection.setReadOnly(false);

网页中有语句 <%@ page contentType="text/html; charset=utf-8"%> 和
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

有如下函数
public class Chinese {

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


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


还是不能插入啊,在数据库里先填入数据再查询时,可能查询但出现中文乱码!!

跪求高手指点了啊...怎样才不出现中文乱码和能把数据插入数据库里
...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
东家阿哥 2008-03-08
  • 打赏
  • 举报
回复
你的MySQL的基本配置文件my.ini是不是拉丁文?改成GBK或者UTF-8.
xuelz 2008-03-04
  • 打赏
  • 举报
回复
Hibernate框架要在Hibernate.cfg.xml里加jdbc:mysql://localhost:3306/goodstable?useUnicode=true&characterEncoding=UTF-8
xuelz 2008-03-04
  • 打赏
  • 举报
回复
没有用Hibernate框架时好像你把改成String(strvalue.getBytes("iso-8859-1")),并且数据库里的显示类型要设置为GBK就可以了;但是用了Hibernate框架要在Hibernate.cfg.xml里加两句代码,具体什么我记不清了,你上网查下就会知道的.
gefengxztg 2008-03-04
  • 打赏
  • 举报
回复
ISO-8859-1
gefengxztg 2008-03-04
  • 打赏
  • 举报
回复
要不换成GBK GB2312其他字符集
gefengxztg 2008-03-04
  • 打赏
  • 举报
回复
是ISO8859-1不是ISO8859_1
langongkun 2008-03-04
  • 打赏
  • 举报
回复
既然都是utf-8你为什么还要进行字符集的转换。并不是所有的utf-8都能转化成ISO8859-1,ISO8859这个字符集的字段比utf-8小。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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