关于如何使用JdbcTemplate实现在WebLogic812,Oracle9i上的CLOB数据的写操作

发表于:2007-07-01来源:作者:点击数: 标签:
进行写操作的方法 import java .sql.*;import org.springframework.jdbc.core.*;import org.springframework.jdbc.core.support. AbstractLobCreatingPreparedStatementCallback;import org.springframework.jdbc.support.lob.LobCreator;import org.springf

进行写操作的方法

import java.sql.*;import org.springframework.jdbc.core.*;import org.springframework.jdbc.core.support. AbstractLobCreatingPreparedStatementCallback;import org.springframework.jdbc.support.lob.LobCreator;import org.springframework.jdbc.support.lob.LobHandler;import org.springframework.jdbc.support.lob.*;import org.springframework.jdbc.support.nativejdbc.*;
public void storeMessateContent(JdbcTemplate jdbcTemplate, String msg) throws      SQLException {    String sql = "insert into test (CONTENT)" +        "values (?)";    try {      OracleLobHandler handler = new OracleLobHandler();      handler.setNativeJdbcExtractor(new WebLogicNativeJdbcExtractor());      this.lobHandler = (LobHandler) handler;      jdbcTemplate.execute(sql,                           new AbstractLobCreatingPreparedStatementCallback(this.          lobHandler) {        protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws            SQLException {          lobCreator.setClobAsString(ps, 1, msg); //设置详细的CLOB字段的内容        }      }      );    }    catch (Exception ex) {      throw new SQLException(          "Update CLOB type column [CONTENT]  ERROR!");    }  }
程序测试环境:welogic812+springframework1.1+Oracle9i


原文转自:http://www.ltesting.net