How to use 'DBCPConnectionPoolLookup' in 'ExecuteGroovyScript' processor?

后端 未结 1 1187
清歌不尽
清歌不尽 2021-01-28 17:24

I want to use \'DBCPConnectionPoolLookup\' controller service in \'ExecuteGroovyScript\' processor. I set \'database.name\' But I get this Error:

This

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 17:40

    I used CTL object and edited the code to solve the problem:

    import groovy.sql.Sql
    
    flowFile = session.get()
    if(!flowFile) return
    def dbConnection = CTL.db.getConnection(flowFile.getAttributes())
    def clientDb = new Sql(dbConnection)
    try {
        def RawData =flowFile.read().getText("UTF-8")
        def JobId = flowFile.ExtractJobId
        def params = [RawData,JobId]
        def result = clientDb.executeInsert("INSERT INTO ExtractFiles (RawData,JobId,CreateTimestamp,UpdateTimestamp) VALUES (?,?,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)",params)
        flowFile.'ExtractFileId' = result[0][0]
        REL_SUCCESS << flowFile
    } catch (Exception e) {
        throw e;
    } finally {
        clientDb.close();
    }
    

    I added clientDb.close() as @daggett said in comments.

    0 讨论(0)
提交回复
热议问题