llaay
280
2020-03-24 11:48:37
4
164

[mybatis] sql 구문오류가 나는데, 조언 부탁드립니다


게시판 검색기능을 구현하려고 합니다

동적SQL 을 이용하려고 하는데, 아래와 같은 오류가 발생합니다

아직 지식이 부족한 탓인지, 원인을 찾기가 어려워서 조언을 부탁드립니다

감사합니다

	<select id="selectAll_review" resultType="BoardBean">
		select * from board ORDER BY board_no DESC
		<trim prefix="WHERE" prefixOverrides="AND|OR">
			<if test="searchType=='board_sub' and keyword != null and keyword != '' ">
				AND board_sub like CONCAT('%', #{keyword}, '%')
			</if>
			<if test="searchType=='board_land' and keyword != null and keyword != '' ">
				AND board_land like CONCAT('%', #{keyword}, '%')
			</if>
			<if test="searchType=='board_theme' and keyword != null and keyword != '' ">
				AND board_theme like CONCAT('%', #{keyword}, '%')
			</if>	
		</trim>
		LIMIT #{startList}, #{listSize}
	</select>


### SQL: select * from board ORDER BY board_no DESC    WHERE  board_sub like CONCAT('%', ?, '%')    LIMIT ?, ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  board_sub like CONCAT('%', 'test', '%') 
		LIMIT 0, 10' at line 2
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  board_sub like CONCAT('%', 'test', '%') 
		LIMIT 0, 10' at line 2] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE  board_sub like CONCAT('%', 'test', '%') 
		LIMIT 0, 10' at line 2
0
0
  • 답변 4

  • 쫑v
    168
    2020-03-24 12:21:16

    쿼리 자체가 잘못 된거 같은데요

    0
  • 쫑v
    168
    2020-03-24 12:23:25

    where 다음에 order by써야 할텐데 

    0
  • llaay
    280
    2020-03-24 12:25:04

    아... 저걸 못봤네요ㅠㅠ

    어제부터 내내 찾던건데.. 기본 문법 실수를.. 감사합니다

    0
  • 쫑v
    168
    2020-03-24 12:27:13

    화이팅... 그럴수 있죠   

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.