【问题标题】:How to update Oracle Clob by using JDBC如何使用 JDBC 更新 Oracle Clob
【发布时间】:2011-12-29 15:34:50
【问题描述】:

正常方式如下:

    pStmt = conn.prepareStatement("SELECT DETAILS FROM PROGRAM_HISTORY WHERE id = 12");
    rset = pStmt.executeQuery();
    Clob detailsClob= rset.getClob(1);
    Writer writer = adapter.getCharacterOutputStream(detailsClob);
    writer.write("add more details"); 

    pStmt = conn.prepareStatement("UPDATE PROGRAM_HISTORY SET DETAILS = ? WHERE ID = 12");
    pStmt.setClob(1, detailsClob);
    pStmt.execute();

这有点复杂,我不需要先阅读然后更新它。就像更新 varchar 一样。

【问题讨论】:

标签: sql database oracle oracle11g


【解决方案1】:

不知道您为什么称其为“正常”方式,但以下内容对我有用。

在更新数据之前不需要对数据进行任何检索。

String value = "So long and thanks for all the fish";
StringReader reader = new StringReader(value);
pStmt = conn.prepareStatement("UPDATE PROGRAM_HISTORY SET DETAILS = ? WHERE ID = 12");
pStmt.setCharacterStream(1, reader, value.length());
pStmt.executeUpdate();

【讨论】:

  • 正常方式意味着我们通常这样做。你的方式看起来不错,你更喜欢选择哪个? “正常”的方式或你的方式,
  • @user872501:我认为“我的方式”是“正常”的方式;)
猜你喜欢
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 1970-01-01
  • 1970-01-01
  • 2012-09-01
  • 1970-01-01
相关资源
最近更新 更多