spring jdbctemplate 는 blob, clob 를 삽입 하고 생 성 된 시퀀스 메 인 키 를 되 돌려 줍 니 다.

1902 단어 springjdbcclobblob
우선 dao 클래스 이름 은 WebContentDao 이 고, 다음은 설 정 된 oracle 시퀀스 입 니 다
<bean id="increWC" class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer">
		<property name="incrementerName" value="s_webcontent"/> <!-- ①      -->
		<property name="dataSource" ref="dataSource"/> 
<!-- ②      -->
</bean>
   WebContentDao    
 @Autowired
 @Qualifier("jdbcTemplate")
 private JdbcTemplate jdbcTemplate;
 
 final Logger logger = LoggerFactory.getLogger(JdbcWebContentDao.class);
 
 @Autowired
 @Qualifier("increWC")
 private DataFieldMaxValueIncrementer increWC;

 @SuppressWarnings("unchecked")
 public int save(final WebContent wc){
     final StringReader sr = new StringReader(wc.getContent());
     final int length = wc.getContent().getBytes().length;
     jdbcTemplate.execute(
          "insert into webcontent(id,content,title) values (?,?,?)",
          new AbstractLobCreatingPreparedStatementCallback(new DefaultLobHandler()) {                        @Override
             int id = increWC.nextIntValue();
             wc.setId(id);      //     id,         id
             prep.setInt(1, id);
             lobCreator.setClobAsCharacterStream(prep, 2, sr, 	length);
             prep.setString(3, wc.getTitle());
             //lobCreator.setBlobAsBinaryStream(ps, 3, blobIs, (int)blobIn.length());  

             }
          }); 
        sr.close();
        return wc.getId();
        
 } 
  Connection ThreadLocal  ,    JdbcTemplate DataFieldMaxValueIncrementer        Connection  ,         !

좋은 웹페이지 즐겨찾기