博客
关于我
Hibernate操作Blob,将Blob转换为String
阅读量:386 次
发布时间:2019-03-05

本文共 764 字,大约阅读时间需要 2 分钟。

public String getScenicCoord(String pk) {
log.debug("根据景区唯一标示获取景区坐标!");
String sql = "select wkt from JQGEO where id = '" + pk + "'";
String result = "";
try {
Connection conn = getSession().connection();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet set = ps.executeQuery();
if (set.next()) {
Blob blob = set.getBlob(1);
InputStream in = blob.getBinaryStream();
int size = in.available();
byte[] by = new byte[size];
in.read(by);
result = new String(by);
} catch (Exception e) {
log.error("根据景区唯一标示获取景区坐标失败!");
result = null;
try {
throw e;
} catch (Exception e1) {
e1.printStackTrace();
result = null;
}
return result;

转载地址:http://rmiwz.baihongyu.com/

你可能感兴趣的文章