jdbc插入修改clob類型的兩種方式


方法一:
Connection con = dbl.loadConnection();
strSql = "insert into table1(id,a) values (1,EMPTY_CLOB())";
dbl.executeSql(strSql);
String str2 = "select a from "
+ " table1 where id=1";

ResultSet rs = dbl.openResultSet(str2);
if(rs.next()){
    CLOB c = ((OracleResultSet)rs).getCLOB("a");
    c.putString(1, "長字符串");
    String sql =
	    "update table1 set a=? where id=1";
    PreparedStatement pstmt = con.prepareStatement(sql);
    pstmt.setClob(1, c);
    pstmt.executeUpdate();
    pstmt.close();
}
con.commit();


方法二:
Connection con = dbl.loadConnection();
CLOB clob   = oracle.sql.CLOB.createTemporary(con, false,oracle.sql.CLOB.DURATION_SESSION);
clob.putString(1,  "長字符串");
Sql1 = "update table1 set a=? where id=1";
PreparedStatement pst = con.prepareStatement(Sql1);
pst.setClob(1, clob);
pst.executeUpdate();
pst.close();
con.commit();

總結:生成一個clob對象,通過預處理的setClob達到插入更新的目的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM