我正在尝试使用针对SQL Server数据库的Groovy SQL运行查询。但是,我收到以下异常:com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported
Grails version: 2.2.5
SQL Server version: 9.0
我从Grails控制台运行的脚本:
import groovy.sql.*
Sql sql = Sql.newInstance(ctx.dataSource_sqlserver)
def query = '''
select
avg(cast(score as decimal)) average_score
from
StudentQuestionScores
where
id in ( :ids )
and question = :question
'''
def ids = Student.list().collect { it.id } // Succeeds
def row = sql.firstRow(query, [ids: ids, question: 'Insert Question Here']) // ERROR
sql.close()
println row.average_score // Never makes it here :(
有谁知道为什么会这样或我如何解决它?谢谢!
堆栈跟踪:
com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java:1117)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObjectNoType(SQLServerPreparedStatement.java:926)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:935)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
at groovy.sql.Sql.setObject(Sql.java:3649)
at groovy.sql.Sql.setParameters(Sql.java:3614)
at groovy.sql.Sql.getPreparedStatement(Sql.java:3875)
at groovy.sql.Sql.getPreparedStatement(Sql.java:3922)
at groovy.sql.Sql.access$900(Sql.java:227)
at groovy.sql.Sql$PreparedQueryCommand.runQuery(Sql.java:4078)
at groovy.sql.Sql$AbstractQueryCommand.execute(Sql.java:4027)
at groovy.sql.Sql.rows(Sql.java:1945)
at groovy.sql.Sql.rows(Sql.java:1835)
at groovy.sql.Sql.rows(Sql.java:1816)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)