使用 getJdbcTemplate().query方法出现error code [17004] 无效的列类型
今天在使用JdbcDaoSupport的以下方法
getJdbcTemplate().query(String sql,Object[] args,ResultSetExtractor rse)
时出现错误,看了很久才发现原来不过是一个低级错误
List<Object> args = new ArrayList<Object>();
if (condition.getFdate() != null) {
args.add(condition.getFdate());
}
if (condition.getChId() != null) {
args.add(condition.getChId());
}
if(condition.getPostTypeCode() != null){
args.add(condition.getPostTypeCode());
}
if (condition.getPlanType() != null) {
args.add(condition.getPlanType());
}
return (List<RecData>) super
.query(needSql, recData,args);
原因:未将args转化为Object[],因为args是List<Object>类型而非Objec[]类型,故弹出以下错误:
解决方法:将语句改为return (List<RecData>) super.query(needSql, recData,args.toArray());即可
2010-08-07 14:14:47,244 ERROR[com.dayee.wintalent.framework.web.interceptor.ExceptionInterceptor] - PreparedStatementCallback; uncategorized SQLException for SQL [SELECT T.F_DATE N_DATE,T.F_POST_TYPE_CODE N_POSTTYPECODE,T.F_CHANNEL_ID N_CHID,T1.F_CHANNEL_DID N_CHDID,T1.F_PLAN_TYPE N_PLANTYPE,T1.F_YEAR_MOTH N_YEARMONTH,T2.F_INSURANCE_CODE N_INSCODE,T2.F_PERSON_NUM N_PERNUM FROM WINTALENT3.T_RECRUITPLAN T,T_RECRUITPLAN_RELATION T1,T_RECRUITPLAN_INSURANCE T2 WHERE 1=1 AND T.F_DATE = ? AND T.F_CHANNEL_ID = ? AND T.F_POST_TYPE_CODE = ? AND T1.F_PLAN_TYPE = ? AND T1.F_REC_RELATION_ID=T.F_ID AND T2.F_REL_RELATION_ID=T1.F_ID ORDER BY T.F_CHANNEL_ID,T1.F_CHANNEL_DID ASC]; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT T.F_DATE N_DATE,T.F_POST_TYPE_CODE N_POSTTYPECODE,T.F_CHANNEL_ID N_CHID,T1.F_CHANNEL_DID N_CHDID,T1.F_PLAN_TYPE N_PLANTYPE,T1.F_YEAR_MOTH N_YEARMONTH,T2.F_INSURANCE_CODE N_INSCODE,T2.F_PERSON_NUM N_PERNUM FROM WINTALENT3.T_RECRUITPLAN T,T_RECRUITPLAN_RELATION T1,T_RECRUITPLAN_INSURANCE T2 WHERE 1=1 AND T.F_DATE = ? AND T.F_CHANNEL_ID = ? AND T.F_POST_TYPE_CODE = ? AND T1.F_PLAN_TYPE = ? AND T1.F_REC_RELATION_ID=T.F_ID AND T2.F_REL_RELATION_ID=T1.F_ID ORDER BY T.F_CHANNEL_ID,T1.F_CHANNEL_DID ASC]; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:641)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:670)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:678)
at com.dayee.wintalent.framework.dao.jdbc.MappingDaoImpl.query(MappingDaoImpl.java:104)