简体   繁体   English

groovy SQL 中的动态插入失败

[英]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我正在阅读这个有用的文档: 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}" ]

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

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