에러 모음

BadSqlGrammarException

junani0v0 2024. 5. 9. 00:10

< 에러 메시지 >

SEVERE: 경로 [/11]의 컨텍스트 내의 서블릿 [pf]을(를) 위한 Servlet.service() 호출이, 근본 원인(root cause)과 함께, 예외 [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE forum.board SET title= ? , content= ? reg_member_seq= '73', update_dtm= DATE_FORMAT(NOW() ,'%Y%m%d%H%i%s') WHERE board_seq= ? AND board_type_seq= ?; ]; nested exception is java.sql.SQLSyntaxErrorException: 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 'reg_member_seq= '73', update_dtm= DATE_FORMAT(NOW() ,'%Y%m%d%H%i%s') WHERE board' at line 1]을(를) 발생시켰습니다.

java.sql.SQLSyntaxErrorException: 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 'reg_member_seq= '73', update_dtm= DATE_FORMAT(NOW() ,'%Y%m%d%H%i%s') WHERE board' at line 1

 

BadSqlGrammarException 

 - JDBC를 사용하여 DB에 쿼리 실행할때 주로 발생

 - SQL문법이 잘못되었거나 DB가 쿼리를 이해하지 못할 때 발생 

< 원인 >

public int updateBoard(HashMap<String, String> params) {
    String sql = "UPDATE forum.board "
               + "SET title=?, content=?, reg_member_seq=73, update_dtm=DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), "
               + "WHERE board_seq=? AND board_type_seq=? ";
    Object[] args = { params.get("title"), params.get("trumbowyg-demo"), params.get("boardSeq"), params.get("boardTypeSeq") };
    return update(sql, args);
}

update_dtm=DATE_FORMAT(NOW(), '%Y%m%d%H%i%s'), 에 뒤에 ,때문에 에러발생 .....

 

그리고 boardSeq와 boardTypeSeq 값을 못가져와 null값이 나옴

< 해결 >

쉼표 제거로 에러는 잡았지만 계속 수정실패가 나와서 확인해보니 boardSeq와 boardTypeSeq 값을 못가져와 null값이 나옴
그래서 edit.do를 수정완료버튼클릭시 값을 보내주게 넘겨줌

<form action="/11/forum/notice/edit.do?boardSeq=${board.boardSeq}&boardTypeSeq=${board.boardTypeSeq}" method ="post">

'에러 모음' 카테고리의 다른 글

CannotLoadBeanClassException  (0) 2024.05.09
XmlBeanDefinitionStoreException  (0) 2024.05.09
TransientDataAccessResourceException  (0) 2024.05.09
EmptyResultDataAccessException  (0) 2024.05.08
TransientDataAccessResourceException  (0) 2024.05.08