Oracle處理Clob類型資料入庫(String入庫)

來源:互聯網
上載者:User

標籤:

從網上尋找一堆參考,要麼語焉不詳,要麼不可行。自己鼓搗了一堆可以正常入庫了。請看最後:

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入庫)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.