mysql保存中文乱码的解决办法

现在继续用起了好久没用的mysql,又碰到了中文问题,客户端编码设为GBK,服务端编码也是GBK,数据库编码也设置了gbk,可是不管怎么做还是显示乱码,最后瞎折腾N多方法,终于解决,只要在程序连接到数据库的地方指定一下编码即可:

public static String driverName = "com.mysql.jdbc.Driver";
 public static String userName = "root";
 public static String userPasswd = "123456";
 public static String dbName = "myBook";
 public static String url = "jdbc:mysql://localhost/" + dbName + "?user="
 + userName + "&password=" + userPasswd
 + "&useUnicode=true&characterEncoding=GBK";

猜你喜欢

转载自kalogen.iteye.com/blog/1748879