MySQL 数据库 JDBC 中文乱码问题
url="jdbc:mysql://localhost:3306/yhcmusic?useUnicode=true&characterEncoding=UTF-8" 源文看这里 http://www.java2000.net/viewthread.jsp?tid=27
url="jdbc:mysql://localhost:3306/yhcmusic?useUnicode=true&characterEncoding=UTF-8" 源文看这里 http://www.java2000.net/viewthread.jsp?tid=27
public static String deCode(String str) {
if (str == null) {
return "";
}
if (str.equals("") || str.equals(" ")) {
return "";
} else {
byte temp[];
try {
temp = str.getBytes("ISO-8859-1");
str = new String(temp, "GBK");
} catch (Exception e) {
System.err.println("convert error: " + e);
}
return str;
}
把从数据库中取出的中文字段都通过这个方法转一码.在显示看看.