用java連接服務器上的Oracle,中文出現亂碼
用sql查看Oracle字符集:
故在連接查詢時需要轉碼,如下:
查詢一條記錄:
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;
}
如上所示,在查詢字符集時需要對結果進行轉碼才能正常顯示