正常方式如下所示:
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一样。
不知道为什么将其称为“正常”方式,但以下内容对我有用。
在更新数据之前,不需要任何数据检索。
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();