[ERROR][MessageApp] MySQLSyntaxErrorException
2020. 11. 29. 21:54ㆍ개발 관련/ERROR
-
메세지 전달 오류
{
"timestamp": "2020-10-19T06:40:44.437+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/messages"
}
terminal :
2020-10-19 15:50:34.835 DEBUG 24320 --- [nio-8080-exec-] app.messages.AuditingFilter
: Request[uri=/messages, method=POST] completed in 2ms
ERROR 내용
- postman에서 send했을 때 메세지가 안받아짐(404 에러... 에러메세지 내용 : 메세지가 이용불가다.)
해결 방법
- 해결 : message가 "No message available"일 때, 경로 확인해보자. -> 해결 x
-
경로오류 - > 해결 x
2020-10-19 23:09:29.737 ERROR 42952 --- [nio-8080-exec-2] app.messages.MessageRepository : Failed to save message
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 ''id', 'text', 'created_date') VALUE (null, 'hello!!', '2020-10-19 23:09:29.411')' at line 1
~
2020-10-19 23:09:29.885 INFO 42952 --- [nio-8080-exec-2] global : msg saved
2020-10-19 23:09:29.885 INFO 42952 --- [nio-8080-exec-2] global : msg saved null
2020-10-19 23:09:29.919 DEBUG 42952 --- [nio-8080-exec-2] app.messages.AuditingFilter : Request[uri=/messages, method=POST] completed in 572ms
ERROR 내용
controller에서 클래스 밖에 있는 경로를 /messages -> / @RequestMapping("/")
-> 이거는 localhost:8080/messages/messages로 보낸 post 대신에 localhost:8080/messages로 보내게 되었다.
welcome도 8080/welcome경로를 가지게 되었다.
조금 더 자세한 에러가 뜨기 시작(controller부터 중간 중간에 log다 때려박음)
에러 해결에는 도움이 되지 않았지만 실행순서는 알 수 있었다.
참고 사이트 : animal-park.tistory.com/182
-
Public Key Retrieval is not allowed - 프로퍼티 오류(url)
{
"timestamp": "2020-10-19T14:50:43.243+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException : Public Key Retrieval is not allowed",
"path": "/messages"
}
2020-10-19 23:50:43.015 ERROR 35392 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;
nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException:: Failed to obtain JDBC Connection;
nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:: Public Key Retrieval is not allowed] with root cause
ERROR 내용
해당 오류는 mysql 8.x 버전 이후로 발생되었다.
- application.properties에 jdbc url 추가
spring.datasource.url=jdbc:mysql://localhost:3306/app_messages?allowPublicKeyRetrieval=true
해결 방법
- 해결 : message가 "No message available"일 때, 경로 확인해보자. -> 해결 x
- 프로퍼티 오류(url)
{
"timestamp": "2020-10-19T15:13:30.559+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Failed to obtain JDBC Connection; nested exception is java.sql.SQLException:
Access denied for user 'root'@'localhost' (using password: YES)",
"path": "/messages"
}
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 ''id', 'text', 'created_date') VALUE (null,
'hello!!', '2020-10-21 14:56:40.856')' at line 1
ERROR 내용
- 잘못된 SQL 문법 에러
해결 방법
- SQL 문법 부분 고치기 -> ' ' 제거
PreparedStatement ps = c.prepareStatement(insertSql, Statement.RETURN_GENERATED_KEYS);
// ps = c.prepareStatement(insertSql, new String[]{"ID"});
String insertSql = "INSERT INTO messages (id, text, created_date) VALUE (null, ?, ?)";
db연결할 때 형식이 잘못되었다. ' 붙이지말고 바로 넣길.