PreparedStatementCallback; bad SQL grammar [delete user where id=?]; nested exception is com.mysql.j

错误代码:

PreparedStatementCallback; bad SQL grammar [delete user where id=?]; nested exception is com.mysql.j
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [delete  user where id=?]; 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 id=3' at line 1
	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
	org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645)
	org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866)
	org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927)
	org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937)
	cn.zut.dao.impl.UserDaoimpl.deleteUser(UserDaoimpl.java:32)
	cn.zut.service.impl.DeleteUserServiceImpl.deleteUser(DeleteUserServiceImpl.java:16)
	cn.zut.web.servlet.DeleteUserServlet.doPost(DeleteUserServlet.java:21)
	cn.zut.web.servlet.DeleteUserServlet.doGet(DeleteUserServlet.java:27)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
这个错误,其实是很低级的错误,,但却又是很难发现的错误。
我是学习了sqlserve后直接拿着sqlserve的语法来使用mysql的,所以·······这个错误真的很可笑
String sql = "delete  user where id=?";
 template.update(sql,id);
 这句sql在sqlserve中是百分百对的,,
 但在mysql中就是错了····
 mysql中的正确写法
 String sql = "delete  from user where id=?";
 template.update(sql,id);
 希望能够帮助到你,让你少踩这种坑。
 加油!
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页