MyBatis问题:无法识别的jdbcType

时间:2015-07-14 19:19:40

标签: mybatis ibatis sqlexception

在尝试将我的应用程序转换为使用MyBatis [之前是iBatis]时,我一直在收到以下错误,尽管尝试对代码进行了这么多种不同的更改:我做错了什么?任何帮助真的真的很棒!!!

Error message:    
`Caused by: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database.  Cause: com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null
`
`### The error may exist in Path-to-XML-File.XML`
`### The error may involve namespace.resultMap-name`
`### The error occurred while executing a query`
`### SQL: {call name-of-stored-proc(?)}`
`### Cause: com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null`
`; uncategorized SQLException for SQL []; SQL state [null]; error code [-4228]; [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null; nested exception is com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null`



XML File:    `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Namespace-name">
	<resultMap id="retrieveReports-results" type="Folder-structure-to-Java-file" autoMapping="true">
		<result property="name" column="REPORT_NAME"/>
		<result property="location" column="REPORT_DIRECTORY"/>
		<result property="key" column="REPORT_KEY"/>
		<result property="executable" column="EXECUTABLE"/>	
		<result property="commandLine" column="COMMAND_LINE"/>	
		<result property="commandLineFormat" column="COMMAND_LINE_FORMAT"/>		
	</resultMap>
<select id="retrieveReports" resultType="java.util.Map" statementType="CALLABLE">
		 {call prc_sel_reports(#{reports,jdbcType=CURSOR,javaType=java.sql.ResultSet,mode=OUT,resultMap=retrieveReports-results})}
	</select>
</mapper>`

Java code:    
		
		try {
				
			List < Report > reports = super.getSqlSession().selectList("retrieveReports");
			if(log.isDebugEnabled()){
				log.debug("Retrieved " + reports.size() + " reports, in method: retrieveReports()");
			}
						
			return reports;
			
			// Attempt to catch different kinds of exceptions.
		} catch (Exception e) {		
			throw new RuntimeException("Exception caught while trying to retrieve reports", e);
		}
	

1 个答案:

答案 0 :(得分:1)

您必须在select语句中指定 parameterType ,无论是map还是自定义类。必须在语句调用上传递实例。 resultType 未使用,无关紧要。

过程实际写入&#34;输入&#34;参数传递给mybatis语句,语句不返回任何内容。

Mapper界面将是:void retrieveReports(Map<String, Object> params); 你的电话:

Map<String, Object> params = new HashMap<String, Object>();
session.selectList("retrieveReports", params);
List<Report> reports = (List<Report>)params.get("reports");

Param也可能是属性为private List<Report> reports;的自定义类型。

相关问题