import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.jdbc.support.lob.OracleLobHandler;
import org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor;
//存
private LobHandler lobHandler = new DefaultLobHandler();;
CommonsDbcpNativeJdbcExtractor nativeJdbcExtractor; //注1
String sql = "insert into gg (test1,colb1) values ('',?)";
final String content = "" //Clob的值
OracleLobHandler handler = new OracleLobHandler();
handler.setNativeJdbcExtractor(this.nativeJdbcExtractor);
this.lobHandler = (LobHandler) handler;
jdbcTemplate.execute(sql, new AbstractLobCreatingPreparedStatementCallback(this.lobHandler){
protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException,
DataAccessException
{
lobCreator.setClobAsString(ps, 1 , content ); //设置详细的CLOB字段的内容
}
}
//取
String sql = "select clob1 from gg where id= ?"
jdbcTemplate.query(sql ,
new Object[] {new Integer(1 )},
new AbstractLobStreamingResultSetExtractor() {
protected void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException {
lobHandler.getClobAsCharacterStream(rs, 1 ); //得到Clob,需要自己处理
}
});
//注1:nativeJdbcExtractor是需要注入的类