STUDY/DBMS

[MyBatis] Could not set parameter at position 1 (values was ~) 에러 해결법

nnh 2023. 4. 11. 11:53
728x90

 

Could not set parameter at position 1 (values was ~)

: 스프링 MyBatis에서 발생하는 위 에러는 주석으로 #{파라미터}를 감쌌을 경우 발생한다.

 

 

 

 

해결 방법은 간단하다.

주석 내에서 해당 파라미터를 제외하거나 또는 주석을 풀어주면 된다.

 

 

 

 

select *
from person p
where 1=1
	and p.id = #{id}
--    and p.age = #{age} -- #{파라미터}를 주석으로 감쌀 경우 -> 에러 발생
    and p.name = #{name}
    
    
--------------------------------------------

-- 해결방법 1 -> 주석 부분 삭제
select *
from person p
where 1=1
	and p.id = #{id}
    and p.name = #{name}
    
-- 해결방법 2 -> 주석 풀기
select *
from person p
where 1=1
	and p.id = #{id}
    and p.age = #{age}
    and p.name = #{name}

 

 

 

 

 

 

간단한 이유인데 자꾸 까먹고 주석처리해서 기억할 겸 기록해보았다.

728x90