oracle merge into函数中插入clob字段

当使用Merge into 函数向ORACLE数据库中插入或更新数据时,报错“ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值”,使用如下方法可以把String转换为clob。

需要引入 JDBC drivers (ojdbc14.jar or ojdbc5.jar)

CLOB tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);//Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();// Write the data into the temporary CLOB
tempClobWriter.write(stringData);// Flush andclose the stream
tempClobWriter.flush();
tempClobWriter.close();//Close the temporary CLOB
tempClob.close();

myStatement.setCLOB(column.order, tempClob);
posted @ 2014-01-20 17:31  shisw  阅读(1547)  评论(0编辑  收藏  举报