错误消息:
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)
}
问题出现在insert语句中作为错误消息,所以我想如何修复这个sql类型的问题?
答案 0 :(得分:0)
使用Sql类上的静态方法将变量包装到数据库已知的类型中。例如,要将GString
打包为varchar
,您可以使用:
import static groovy.sql.Sql.*
....
sql.eachRow("select * from foo where name = ${VARCHAR(myVar)}")