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

80酷酷网    80kuku.com

  oracle|web|数据
进行写操作的方法

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




分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: