正常方式如下:
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();