JavaEE之ybatis遇到的坑1

JavaEE之Mybatis遇到的坑1

在写好了相关的逻辑代码之后出现了如下报错

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 '"user" (username,password,phone,email) VALUES('TWG','123','15107793356','[email protected]' at line 1
; 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 '"user" (username,password,phone,email) VALUES('TWG','123','15107793356','[email protected]' at line 1
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

于是我几次检查了以下XML中的SQL语句发现并没什么问题

<mapper namespace="com.twgfs.ui.dao.LoginRegistServiceDao">

    <insert id="Registing">
        INSERT INTO "user" (username,password,phone,email) VALUES(#{username},#{password},#{phone},#{email})
    </insert>
</mapper>

所以就只好一个一个的试,最后才发现原来是在写INSERTINTO的时候 自动提示了表名user然后我就顺手按了一下回车于是就写成了带引号的 “user” 的表名所以就一直提示错误!

结论:在用Mybatis写SQL语句的时候,注意自动提示的表名可能会带上 “” 这样就会发现很难找出错误所以还是手动写比较好!

发布了19 篇原创文章 · 获赞 7 · 访问量 6637

猜你喜欢

转载自blog.csdn.net/William_TWG/article/details/84565459