標籤:
從網上尋找一堆參考,要麼語焉不詳,要麼不可行。自己鼓搗了一堆可以正常入庫了。請看最後:
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 updateString update_sql = "select V_INFO from CP_V_INFO where ID=‘"+v7Info.getId()+"‘ 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(); } } } }
千辛萬苦倒騰入庫之後,同事說了一句“幹嘛要改底層代碼?”。啪啪啪一通悅耳的鍵盤聲之後,改回原來的方式。該欄位用 String 正常插入。結果是:正常入庫了。、、、、、、、、、、淚奔!!!!
String sql = "insert into CP_V_INFO" + "(ID, "+ …… "V_INFO, "+ …… "VERSION)values(?,?,?,?,?,?,?,?,?,?," + "?,?,?,?,?,?,?,?,?,?," + "?,?,?,?,?,?,?,?,?,?," + "?)"; this.cdcDao.executeSQL(sql, v7Info.getId(), …… v7Info.getvInfo(),//String類型 …… v7Info.getVersion());/* ******** end **********/
Oracle處理Clob類型資料入庫(String入庫)