现在的位置: 首页 > 综合 > 正文

查询Blob字段转String

2013年02月25日 ⁄ 综合 ⁄ 共 625字 ⁄ 字号 评论关闭

public AutoDto queryOrderDetail(Long crmInfId) throws Exception {
  AutoDto dto = new AutoDto();
  Connection conn = null;
  PreparedStatement ps = null;
  ResultSet rs = null;
  try {
   conn = getConnection();
   ps = conn.prepareStatement("select a.CONTENT from inf_crm_mission a where a.id = "
       + crmInfId + " for update ");
   rs = ps.executeQuery();
   if (rs.next()) {
    java.sql.Blob blob = rs.getBlob(1);
    InputStream ins = blob.getBinaryStream();
    byte[] c = new byte[(int) blob.length()];
    ins.read(c);
    String data = new String(c);
    dto.setReturnContent(data);
    // 依次关闭
    ins.close();
    rs.close();
   }
   return dto;
  } finally {
   cleanUp(conn, null, ps, rs);
  }
 }

 

抱歉!评论已关闭.