[error] Could not set parameters for mapping 부적합한 열 유형:1111 에러 해결하기

HMS·2022년 8월 31일
0

Could not set parameters for mapping 에러 발생

org.apache.ibatis.exceptions.PersistenceException:
Error updating database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='lectureInstructor', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 부적합한 열 유형: 1111
The error may involve defaultParameterMap
The error occurred while setting parameters

원인

이 에러는 MyBatis가 데이터베이스 열에 대한 매핑 문제로 인해 SQL 문을 실행하지 못할 때 발생한다.

이 에러의 메시지를 살펴보면, 'Could not set parameters for mapping'라는 메시지와 'Error setting null for parameter #2 with JdbcType OTHER'라는 메시지가 있다.
이것은 MyBatis가 인자 매핑에 문제가 있다는 것을 나타낸다.
MyBatis가 매핑한 두 번째 매개 변수에 null 값을 할당할 수 없으며, 이를 JDBC 유형 OTHER와 함께 사용할 수 없기 때문에 오류가 발생했다.

해결책

부적합한 열 유형:1111 에러의 다양한 원인들

  1. 넘어가는 데이터 타입이 다를 경우
  2. Map을 파라미터로 넘겼을 시에 해당 맵안에 파라미터가 Null일 경우
  3. request 파라미터 값이 없을 경우
  4. form id & name 값 미지정시
  5. ajax를 사용했을 겨우에 value가 하나라도 null일 경우.

대부분 인터넷에서는 오타나 데이터 타입이 다를 경우에 생긴다고 한다.

<tr>
	<td>강사명</td>
	<td>
		<input type="text" name="instructorName">
	</td>
</tr>

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String lectureName = request.getParameter("lectureName");
		String lectureInstructor = request.getParameter("lectureInstructor");
		String lectureIntroduce = request.getParameter("lectureIntroduce");

나의 경우는 jsp에서 가져올 강사명 변수이름인 instructorName과 doPost에서 request로 받는 lectureInstructor이 달라 부적합한 열 유형 판정이 나왔다.
둘중하나를 수정해 변수명을 맞춰줌으로써 해결할 수 있었다.

출처: https://koeiking11.tistory.com/entry/부적합한-열-유형-1111 [코더에서 개발자로 가는길.:티스토리]

profile
안녕하세요

0개의 댓글