java获取mysql Blob数据乱码 15
java获取Blob数据产生乱码,求解决。代码如下:SourcePassportDetailsourcePassportDetail=passportDetailDao....
java获取Blob数据产生乱码,求解决。
代码如下:
SourcePassportDetail sourcePassportDetail = passportDetailDao.findByPassportId(Long.valueOf(id));
Blob blob = sourcePassportDetail.getHobbyIds();
String note = null;
try {
InputStream is = blob.getBinaryStream();
ByteArrayInputStream bais = (ByteArrayInputStream)is;
byte[] byte_data = new byte[bais.available()];
bais.read(byte_data, 0,byte_data.length);
note = new String(byte_data,"utf-8");
System.out.println(note);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
上图为乱码结果 展开
代码如下:
SourcePassportDetail sourcePassportDetail = passportDetailDao.findByPassportId(Long.valueOf(id));
Blob blob = sourcePassportDetail.getHobbyIds();
String note = null;
try {
InputStream is = blob.getBinaryStream();
ByteArrayInputStream bais = (ByteArrayInputStream)is;
byte[] byte_data = new byte[bais.available()];
bais.read(byte_data, 0,byte_data.length);
note = new String(byte_data,"utf-8");
System.out.println(note);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
上图为乱码结果 展开
若以下回答无法解决问题,邀请你更新回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询