关于mysql插入问题和乱码
我在应用中,不能插入,只能查询但查询出来中文乱码
我的问题大致如下
其中数据库 设置为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 "";
}
}
还是不能插入啊,在数据库里先填入数据再查询时,可能查询但出现中文乱码!!
跪求高手指点了啊...怎样才不出现中文乱码和能把数据插入数据库里