简体   繁体   English

使用Clob进行Groovy批量更新

[英]Groovy Batch Update with Clob

I'm trying to run a batch update using a clob, but my table is getting updated with the clobs memory address instead of the clob value. 我正在尝试使用clob运行批量更新,但我的表正在使用clobs内存地址而不是clob值进行更新。

def updateCounts = sql
    .withBatch('UPDATE my_table SET clob_column = ? WHERE id = ?') { stmt ->
        fileList.each { fileName->

            Clob commentClob = CLOB.createTemporary(sql.getConnection(), false, CLOB.DURATION_SESSION)
            CSVReader reader = new CSVReader(
                new FileReader(theInfoFile), 
                CSVParser.DEFAULT_SEPARATOR, 
                CSVParser.DEFAULT_QUOTE_CHARACTER, 1)
            String[] row;

            while ((row = reader.readNext()) != null) {
                commentClob.truncate(0)
                commentClob.setString(1,"${row[17]}")
                stmt.addBatch([commentClob,row[0]])
            }
        }
}

The value that I'm seeing in the database is "oracle.sql.CLOB@15500a8". 我在数据库中看到的值是“oracle.sql.CLOB@15500a8”。 Any suggestions on how to handle the clob value? 有关如何处理clob值的任何建议?

Untested, but you could try the oracle specific characterOutputStream : 未经测试,但您可以尝试oracle特定的characterOutputStream

commentClob.characterOutputStream << row[17]

it's possible you would need to type the variable as: 您可能需要键入变量:

OracleClob commentClob = ...

instead of: 代替:

Clob commentClob = ...

but groovy being groovy, you probably would not need to. 但是时髦的常规,你可能不需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM