当前位置:首页 > 开发 > 数据库 > 正文

java 处理 BLOB OutputStream(插入空的Blob字段到表中)

发表于: 2015-07-08   作者:ccfangle   来源:转载   浏览次数:
摘要: 1.插入占位数据: insert into TEST_CUICF(t1,t2) values(12,empty_blob()) 2.获得占位数据: select t1,t2 from TEST_CUICF t for update   BLOB oracleBlobMockIn = oracleBlobMockIn = control.createMock(BLOB.class

1.插入占位数据:

insert into TEST_CUICF(t1,t2) values(12,empty_blob())

2.获得占位数据:

select t1,t2 from TEST_CUICF t for update

 

BLOB oracleBlobMockIn = oracleBlobMockIn = control.createMock(BLOB.class);

...

  oracleBlobMockIn.getBinaryStream();
  expectLastCall().andReturn(new FileInputStream(inPdfFile)).times(1);

...

  ResultSet rs = st.executeQuery(sql);
  BLOB oracleBlobMockOut = null;
  if (rs.next()) {
   rs.getString("t1");
   oracleBlobMockOut = (BLOB) rs.getBlob("t2");
  }
...

  control.replay();
  Watermark.addPdfWatermark(oracleBlobMockIn, oracleBlobMockOut, markImagePath);
  control.verify();
  control.reset();

 

3.应用 输出流 (增加水印处理)

 public static void addPdfWatermark(BLOB inputPdfFileBlob, BLOB outPdfFileBlob, String markImagePath) throws Exception {
  if (null == WATERMARK_IMAGE) {
   logger.info("watermark_image inital~~");
   WATERMARK_IMAGE = Image.getInstance(markImagePath);
   WATERMARK_IMAGE.setAbsolutePosition(10, 250);
  }

  PdfReader reader = null;
  PdfStamper stamp = null;
  try {
   reader = new PdfReader(inputPdfFileBlob.getBinaryStream(), "PDF".getBytes());
   stamp = new PdfStamper(reader, outPdfFileBlob.getBinaryOutputStream()); //获得输出流

   int numberOfPages = reader.getNumberOfPages();
   for (int i = 1; i <= numberOfPages; i++) {
    PdfContentByte under = stamp.getUnderContent(i);
    under.addImage(WATERMARK_IMAGE);
   }

  } finally {
   stamp.close();
  }
 }

4.关闭连接

  con.commit();

  con.close();

 

java 处理 BLOB OutputStream(插入空的Blob字段到表中)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
运行blob测试程序,数据有点大,32M,结果报出了下面的异常信息: com.mysql.jdbc.PacketTooBigExcept
数据库表: TpkXw.java private byte[] xwnr; private String xwnrstr; public byte[] getXwnr() { r
来自:http://esffor.iteye.com/blog/168264 数据库脚本: create table testcb(id varchar ( 32 )
数据库脚本: create table testcb(id varchar ( 32 ) primary key ,name varchar ( 32 ),photo blo
数据库脚本: create table testcb(id varchar ( 32 ) primary key ,name varchar ( 32 ),photo blo
数据库脚本: create table testcb(id varchar ( 32 ) primary key ,name varchar ( 32 ),photo blo
来自:http://esffor.iteye.com/blog/168264 数据库脚本: create table testcb(id varchar ( 32 )
字段设置如图: datawindow语法 release 8; datawindow(units=0 timer_interval=0 color=15793151 p
在使用IReport打印报表的时候往往需要从数据库中读取Blob字段,然后将其展示为图片. 接下来以数据库
来自:http://esffor.iteye.com/blog/168264 数据库脚本: create table testcb(id varchar ( 32 )
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号