Java通过JDBC查询SqlServer乱码,中文乱码。

原因是自己封装的工具类中有进行转码,检查之后问题解决,正常JDBC直链很小几率会出现乱码问题,在这里附上一份Java转码的语句。

Java通过JDBC查询SqlServer乱码,中文乱码。_第1张图片

System.out.println(new String(str.getBytes("GBK"),"UTF-8"));
System.out.println(new String(str.getBytes("GBK"),"GB2312"));
System.out.println(new String(str.getBytes("GBK"),"ISO8859-1"));


System.out.println(new String(str.getBytes("GB2312"),"UTF-8"));
System.out.println(new String(str.getBytes("GB2312"),"ISO8859-1"));
System.out.println(new String(str.getBytes("GB2312"),"GBK"));


System.out.println(new String(str.getBytes("ISO8859-1"),"UTF-8"));
System.out.println(new String(str.getBytes("ISO8859-1"),"GB2312"));
System.out.println(new String(str.getBytes("ISO8859-1"),"GBK"));


System.out.println(new String(str.getBytes("UTF-8"),"GB2312"));
System.out.println(new String(str.getBytes("UTF-8"),"GBK"));
System.out.println(new String(str.getBytes("UTF-8"),"ISO8859-1"));

你可能感兴趣的:(java,sqlserver,数据库)