解决插入数据库的中文乱码问题
写一个方法,插入数据库的时候用下面的方法转换一下就可以了。
public static String changeCode(String str){ String temp = null; try{ byte[] temp_s = str.getBytes("ISO8859-1"); temp = new String(temp_s); System.out.println(temp); }catch(Exception e){ System.out.println(e); } return temp; }
经过上面的方法得到的temp字符串可以顺利的插入数据库而不会产生乱码