blob我是用来存放大字符串的。在用weblogic9+linux+oracle9的过程中,从blob中读取的中文为乱码;
如果是weblogic9+linux+oracle9,则从blob中读取的中文不是乱码。
String pstmt_str = "select ot_history from Operationtache where b_code=? and ts_code=?";
PreparedStatement pstmt = conn.prepareStatement(pstmt_str);
pstmt.setString(1, b_code);
pstmt.setString(2, ts_code);
ResultSet rset = pstmt.executeQuery();
if (rset.next()) {
Blob blob = rset.getBlob("ot_history");
byte[] bytes = blob.getBytes(1, (int)blob.length());
if(这儿应该写什么) {
content = new String(bytes, "GBK");
}else {
content = new String(bytes;
}
}
pstmt.close();
如果是这样写,则显示为正确编码;但我这块代码为共用代码,涉及地方很多,所以我想知道有没办法知道byte[] bytes 的编码格式,如果需要转换则转换。
还有个奇怪的现象,如果是读取以前的数据是乱码,如果是自己存放的数据,则显示正确。
如果是weblogic9+linux+oracle9,则从blob中读取的中文不是乱码。
String pstmt_str = "select ot_history from Operationtache where b_code=? and ts_code=?";
PreparedStatement pstmt = conn.prepareStatement(pstmt_str);
pstmt.setString(1, b_code);
pstmt.setString(2, ts_code);
ResultSet rset = pstmt.executeQuery();
if (rset.next()) {
Blob blob = rset.getBlob("ot_history");
byte[] bytes = blob.getBytes(1, (int)blob.length());
if(这儿应该写什么) {
content = new String(bytes, "GBK");
}else {
content = new String(bytes;
}
}
pstmt.close();
如果是这样写,则显示为正确编码;但我这块代码为共用代码,涉及地方很多,所以我想知道有没办法知道byte[] bytes 的编码格式,如果需要转换则转换。
还有个奇怪的现象,如果是读取以前的数据是乱码,如果是自己存放的数据,则显示正确。
weblogic9+linux+oracle9的过程中,从blob中读取的中文为乱码;
如果是
weblogic9+linux+oracle9,则从blob中读取的中文不是乱码。 很抱歉,我看不出这2行有任何区别??byte[] 是无法区分编码的,那是存入数据时要注意的事情,而不是读取的时候!
weblogic9+linux+oracle9的过程中,从blob中读取的中文为乱码;
如果是
weblogic9+windows xp+oracle9,则从blob中读取的中文不是乱码。
window xp不是乱码是因为默认是GBK码存进去的吧
linux下你可以修改weblogic9的执行用户的.profile文件,最后加上
export LANG=zh_CN.GBK,再重新启动weblogic看看效果。或者修改weblogic的jvm参数加上 -Dfile.encoding=GBK也应该可以解决你的问题
http://www.mandarintools.com/download/SinoDetect.java