日期:2014-05-19  浏览次数:20680 次

上传附件到数据库Clob类型字段下,出现乱码,,,求解
OutputStream outStream = this.getClob((Long) listid.get(i)).getAsciiOutputStream();
InputStream input = (InputStream) list.get(i);
byte[] buffer = new byte[input.available()];
String str = new String(buffer, "GBK");
byte buffers[] = str.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(buffers);

int coun = 0;
while ((coun = input.read(buffers)) > 0) {
outStream.write(buffers, 0, coun);
}
outStream.close();
bais.close();

------解决方案--------------------
处理Clob还得考虑数据库端支持什么字符集的问题。。。

还不如直接用Blob,让数据库别考虑字符集和转码了。
------解决方案--------------------
那么就慢慢来排查。

首先,直接用数据库工具,去看看数据库中Clob字段中的内容,是不是乱码。
至少要保证你写进去的时候,信息是正确的。

然后才是检查在读取的时候,所选择的转码方式是否合适。