java.sql.SQLException: The value supplied cannot be converted to DECIMAL 解决方法
2012-01-04 21:10
621 查看
Java代码
SELECT max(measure_time) as str2,avg(temperature) as stravg FROM weather_equipment_data_1 WHERE 1>0 AND MEASURE_TIME BETWEEN '2008-04-17 10:12:44' AND '2008-04-17 10:14:44' group by ((DATEDIFF(second,'1970-01-01',MEASURE_TIME)-1) / 5)
这段sql描述了按在这两个时间范围之内按5秒钟统计temperature平均值。
在sqlserver中运行一切正常。
但是在hibernate中执行Query query = session.createSQLQuery(sql)却报错为
java.sql.SQLException: The value supplied cannot be converted to DECIMAL
解决方法:
Java代码
Query query = session.createSQLQuery(sql)
.addScalar("str2",Hibernate.STRING)
.addScalar("stravg",Hibernate.STRING);
将两个查询字段分别强制转为hibernate string之后运行正常。
SELECT max(measure_time) as str2,avg(temperature) as stravg FROM weather_equipment_data_1 WHERE 1>0 AND MEASURE_TIME BETWEEN '2008-04-17 10:12:44' AND '2008-04-17 10:14:44' group by ((DATEDIFF(second,'1970-01-01',MEASURE_TIME)-1) / 5)
这段sql描述了按在这两个时间范围之内按5秒钟统计temperature平均值。
在sqlserver中运行一切正常。
但是在hibernate中执行Query query = session.createSQLQuery(sql)却报错为
java.sql.SQLException: The value supplied cannot be converted to DECIMAL
解决方法:
Java代码
Query query = session.createSQLQuery(sql)
.addScalar("str2",Hibernate.STRING)
.addScalar("stravg",Hibernate.STRING);
将两个查询字段分别强制转为hibernate string之后运行正常。
相关文章推荐
- java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.String错误的解决方法
- java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date 解决方法
- java.math.BigDecimal cannot be cast to java.lang.String解决方法
- org.json.JSONException: Value ok of type java.lang.String cannot be converted to JSONObject:
- sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class异常解决方法
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- Value of type java.lang.String cannot be converted to JSONObject
- java.sql.SQLException: Cannot convert value '2017-07' from column 6 to TIMESTAMP.
- weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB cannot be cast to oracle.sql.BLOB 不改程序解决方法
- java.sql.SQLException: Value'0000-00-00'错误解决方法
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- Android N requires the IDE to be running with Java 1.8 or later 解决方法
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- The type java.lang.Object cannot be resolved解决方法
- new JSONObject(str)无法解析 报错:org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- java java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 5 to TIMESTAMP.
- The type java.lang.Object cannot be resolved解决方法
- 解决mysql java.sql.SQLException: The server time zone value‘XXXXXX' is unrecognized or represents...
- java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist 解决方法