Reputation: 81
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!
Upvotes: 0
Views: 134
Reputation: 20699
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}" ]
Upvotes: 2