簡體   English   中英

groovy insert語句無法推斷用於org.codehaus.groovy.runtime.GStringImpl實例的SQL類型

[英]groovy insert statement Can't infer the SQL type to use for an instance of org.codehaus.groovy.runtime.GStringImpl

錯誤信息:

URI
/racetrack/readUserRole/index
Class
org.postgresql.util.PSQLException
Message
Can't infer the SQL type to use for an instance of org.codehaus.groovy.runtime.GStringImpl. Use setObject() with an explicit Types value to specify the type to use

碼:

a="col01"
b="col${usercol}"
c="col${rolecol}"
sql.eachRow("select $a,$b,$c from read_csv where col01=? and col${usercol}!=? ", [file.name,""]) {

    t="${it."$a"}"
    i="${it."$b"}"
    r="${it."$c"}"
    t.getClass() == String
    i.getClass()== String
    r.getClass()== String

    def list2=[t,i,r]
    println list2
    sql.execute('insert into read_user_role(version,roledata,textname,userdata)'+
            'VALUES (0,?,?,?)', list2)
}

該問題發生在插入語句作為錯誤消息,所以我應該如何解決此SQL類型的問題?

Sql類上使用靜態方法將變量包裝為數據庫已知的類型。 例如,要將GString包裝為varchar ,可以使用:

import static groovy.sql.Sql.*

....

sql.eachRow("select * from foo where name = ${VARCHAR(myVar)}")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM