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达到插入更新的目的

posted @   jlins  阅读(8104)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示