开发者

Use stored procedure when getting blob at spring mvc

I wanted to learn how to use Stored Procedure when inserting BLOB data on my MSSQL Table.

final File blobIn = new File("spring2004.jpg");
final InputStream blobIs = new FileInputStream(blobIn);
final File clobIn = new File("large.txt");
final InputStream clobIs = new FileInputStream(clobIn);
final InputStreamReader clobReader = new InputStreamReader(clobIs);
jdbcTemplate.execute(
  "INSERT INTO lob_table (id, a_clob, a_blob) VALUES (?, ?, ?)",
  new AbstractLobCreatingPreparedStatementCallback(lobhandler) {                         (1)
      protected void setValues(PreparedStatement ps, LobCreator lobCreator) 
          throws SQLException {
        ps.setLong(1, 1L);
        lobCreator.setClobAsCharacterStream(ps, 2, clobReader, (int)clobIn.length());    (2)
        lobCreator.setBlobAsBinaryStream(ps, 3, blobIs, (int)blobIn.length());           (3)
      }
  }
);
blob开发者_运维百科Is.close();
clobReader.close();

The spring framework 2.5 documentation uses jdbc template. But this is a NO-NO in my case. I hope somebody could share their insights on how to do insert and retrieve the data as an inputstream.

I have been trying to google for the answer but not enough resource on this can be found.


You can try with Spring + JPA with a native query or with JpaDaoSupport.

There are good answers in the following links:

  • Native query
  • JpaDaoSupport
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜