[英]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.