应该保证数据在插入数据库之前是中文的,如果不是中文则再进行转码处理: public String toCN(String str) {
if(str==null)
return str;
// 定义变量(供返回值时使用)
String re = null;
try {
// 将str重新编码(编码方式可以用gb2312,GBK 多试试)
re = (new String(str.getBytes("ISO8859-1"))).trim();
} catch(Exception ex) {
// 将异常提示信息输出到屏幕
System.out.println(ex.getMessage());
}
// 如果re为null,则返回原str,否则返回处理后的结果re.
return (re==null) ? str : re;
} // End method toCN
if(str==null)
return str;
// 定义变量(供返回值时使用)
String re = null;
try {
// 将str重新编码(编码方式可以用gb2312,GBK 多试试)
re = (new String(str.getBytes("ISO8859-1"))).trim();
} catch(Exception ex) {
// 将异常提示信息输出到屏幕
System.out.println(ex.getMessage());
}
// 如果re为null,则返回原str,否则返回处理后的结果re.
return (re==null) ? str : re;
} // End method toCN
我怎么从来没有考虑过这类问题呢?
不管是存入数据库或者是取出来显示!
我用的是MySQL和SQL Server