从网上查找一堆参考,要么语焉不详,要么不可行。自己鼓捣了一堆可以正常入库了。请看最后:
insert into CP_V_INFO" +
"(ID, "+
"PROJECT_ID, "+
……
"V_INFO, "+
……
"VERSION)values(?,?,?,?,?,?,?,?,?,?," +
"?,?,EMPTY_CLOB(),?,?,?,?,?,?,?," +
"?,?,?,?,?,?,?,?,?,?," +
"?)";
this.cdcDao.executeSQL(sql, v7Info.getId(),
v7Info.getProjectId(),……
);
//先插入该数据,在该字段用 EMPTY_CLOB() 插入。
//然后 for update
String update_sql = "select V_INFO from CP_V_INFO where for update";
this.cdcDao.executeClobSQL(update_sql,"V_INFO",v7Info.getvInfoStr());
/**
*
* @Method: executeClobSQL
* @Description: 更新Clob字段
* @param update_sql
* @param column 字段名称 data 该字段数据
* @return
* @throws SQLException
* @throws Exception
* @author liuz
* @date 2016-3-28
*/
public void executeClobSQL(String update_sql,String column,String data) throws SQLException, Exception {
if(((MyJdbcTemplate)this.getJdbcTemplate()).isNEED_ENCODE()){
update_sql = new String(update_sql.getBytes(((MyJdbcTemplate)this.getJdbcTemplate()).getAPP_ENCODE()),((MyJdbcTemplate)this.getJdbcTemplate()).getDB_ENCODE());
}
PreparedStatement p = null;
ResultSet rs = null;
try {
Connection conn = this.getConnection();
conn.setAutoCommit(false);
p = paserSQL(conn, update_sql);
rs = conn.createStatement().executeQuery(update_sql);
if (rs.next()) {
/* 取出此CLOB对象 */
Oracle.sql.CLOB clob = null;
clob = (oracle.sql.CLOB) rs.getClob(column);
/* 向CLOB对象中写入数据 */
BufferedWriter out = new BufferedWriter(clob
.getCharacterOutputStream());
out.write(data);
out.flush();
out.close();
}
rs.close();
conn.commit();
conn.setAutoCommit(true);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (p != null) {
try {
p.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}