更新blob数据以流的形式进行数据的存储

来源:互联网 发布:mvc.ezui数据表格 编辑:程序博客网 时间:2024/06/05 03:38
public boolean updateCombContent(Session session,String unid){
  JdbcTemplate jdbcTemplate = JDBCTool.getAppDBTool(session);
  PreparedStatement ps = null;
  String combContent=this.getCombContent(session, unid);
  int rs = 0;
  try {
   jdbcTemplate.open();
   String sql = "update oa_maganize d set d.maganize_combcontent=? where d.maganize_unid='"
    + unid + "'";
    ps = jdbcTemplate.getConnection().prepareStatement(sql);
     byte[] bytes_content = combContent.getBytes(); //将文本内容转换成字节流
     ByteArrayInputStream bytecontent = new ByteArrayInputStream(bytes_content); //进行字节流的存取
     ps.setBinaryStream(1, bytecontent, bytes_content.length); //进行数据操作
     rs=ps.executeUpdate();
     if(rs<=0){
     return false;
     }
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    if (ps != null) {
     ps.close();
    }
    if (jdbcTemplate != null) {
     jdbcTemplate.close();
    }
   } catch (Exception e) {
    e.printStackTrace();
    return false;
   }
  }
  return true;
 
 }
0 0
原创粉丝点击