首先,创建一个含CLOB字段的表:
create table test (id INTEGER, content clob);
然后插入空值
String strSql = “INSERT INTO TEST(id,content) values(‘0001’,?) ”;
con.setAutoCommit(false); //conn为Connection对象
//创建并实例化一个CLOB对象
CLOB clob = new CLOB((OracleConnection)con);
clob = oracle.sql.CLOB.createTemporary((OracleConnection)con,true,1);
//对CLOB对象赋值
clob.putString(1,formateSingleQuotes(Content));
OracleConnection OCon = (OracleConnection)con;
OraclePreparedStatement pstmt = (OraclePreparedStatement)OCon.prepareCall(strSql);
pstmt.setCLOB(1,clob);
int i = pstmt.executeUpdate();
pstmt.close();
OCon.commit();
OCon = null;
con = null;
com.mchange.v2.c3p0.impl.NewProxyConnection cannot be cast to oracle.jdbc.driver.OracleConnection异常,自己尝试了半天又在网上找到了解决方案:
- added
import org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor;
- replaced the following code in nullSafeSet method from JGeometryType:
OracleConnection connection = (OracleConnection) preparedStatement.getConnection();
with:
C3P0NativeJdbcExtractor cp30NativeJdbcExtractor = new C3P0NativeJdbcExtractor();
OracleConnection connection = (OracleConnection) cp30NativeJdbcExtractor.getNativeConnection(preparedStatement.getConnection());