用java连接服务器上的Oracle,中文出现乱码
用sql查看Oracle字符集:
select userenv('language') from dual
得到us7ascii
故在连接查询时需要转码,如下:
查询一条记录:
Connection conn=null;
PreparedStatement pstmt = null;
ResultSet rs=null;
try {
String sql="select B from tabA where A=1111";
conn=ds.getConnection();
pstmt = conn.prepareStatement(sql);
rs=pstmt.executeQuery();
String s;
if (rs.next()){
s=new String(rs.getString(1) .getBytes("ISO-8859-1"), "GBK");
}
catch (Exception e) {
}
finally {
rs.close;
pstmt.close;
coon.close;
}
如上所示,在查询字符集时需要对结果进行转码才能正常显示