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 '}' at line 1

发布时间 2023-06-29 10:42:08作者: YE-

问题

报错代码

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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 '}' at line 1
### The error may exist in org/example/mapper/UserMapper.java (best guess)
### The error may involve org.example.mapper.UserMapper.select-Inline
### The error occurred while setting parameters
### SQL: select * from po_user where username = ? and password = ?}
### Cause: 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 '}' at line 1
	org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)
	org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	jdk.proxy4/jdk.proxy4.$Proxy32.select(Unknown Source)
	org.example.service.Impl.UserServiceImpl.login(UserServiceImpl.java:21)
	org.example.web.servlet.LoginServlet.doGet(LoginServlet.java:23)
	org.example.web.servlet.LoginServlet.doPost(LoginServlet.java:62)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	org.example.web.filter.LoginFilter.doFilter(LoginFilter.java:28)

原因:

这里多加了一个大括号

解决方法

出错的sql地方是在SQL语句这里,修改可以了