简体   繁体   中英

Dynamic insert fails in groovy SQL

I'm trying to insert into my table a dynamic input.

def SYS_idValue = '9999999'

try{
    //Open connection to CCM
    connection = Sql.newInstance(CCMJdbcUrl, CCMUsername, CCMPassword, CCMJdbcDriver)

    def Mytable = 'INSERT INTO INTELTABLE (SYS_ID) VALUES (?)'
    connection.execute Mytable, [${SYS_idValue}]
       
    connection.close()
        
}  catch (Exception e) {
    println("Exception" + e)
    connection.close()
}

I'm reading this useful documentation: https://livebook.manning.com/book/groovy-in-action-second-edition/chapter-13/106

But can't figure it out. No errors so far, but don't work

This method works but i have to define the input.

connection.execute """INSERT INTO INTELTABLE (SYS_ID)
                    values ('3333333')"""

Any ideas? Thank you guys!

This thing won't even compile:

connection.execute Mytable, [${SYS_idValue}]

Possible options are:

connection.execute Mytable, [ SYS_idValue ]
//or
connection.execute Mytable, [ "${SYS_idValue}" ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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