今天做分页查询数据库中的信息时,当查询数据库中不存在的数据时,页面就会报错,最终发现是分页时的问题,当查询到当查询到的数据为0时,总页数是0,当前页数据的起始就是-5,去数据库中查询就会报错,当查询数据为0时将总页数设置为1就可以解决错误。
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
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 ‘-5, 5’ at line 5
The error may exist in file [D:\develop\apache-tomcat-8.5.39\webapps\ROOT\WEB-INF\classes\edu\whut\dao\UserDao.xml]
The error may involve edu.whut.dao.UserDao.findAllByPage-Inline
The error occurred while setting parameters
SQL: select * from t_user where username like concat(’%’, ?, ‘%’) limit ?, ?
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 ‘-5, 5’ at line 5
; bad SQL grammar []; 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 ‘-5, 5’ at line 5
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
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:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
Root Cause
org.springframework.jdbc.BadSqlGrammarException:
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 ‘-5, 5’ at line 5
The error may exist in file [D:\develop\apache-tomcat-8.5.39\webapps\ROOT\WEB-INF\classes\edu\whut\dao\UserDao.xml]
The error may involve edu.whut.dao.UserDao.findAllByPage-Inline
The error occurred while setting parameters
SQL: select * from t_user where username like concat(’%’, ?, ‘%’) limit ?, ?
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 ‘-5, 5’ at line 5
; bad SQL grammar []; 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 ‘-5, 5’ at line 5
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)
org.mybatis.spring.SqlSessionTemplate
S
q
l
S
e
s
s
i
o
n
I
n
t
e
r
c
e
p
t
o
r
.
i
n
v
o
k
e
(
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
j
a
v
a
:
440
)
c
o
m
.
s
u
n
.
p
r
o
x
y
.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) com.sun.proxy.
SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)com.sun.proxy.Proxy12.selectList(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
org.apache.ibatis.binding.MapperProxy
P
l
a
i
n
M
e
t
h
o
d
I
n
v
o
k
e
r
.
i
n
v
o
k
e
(
M
a
p
p
e
r
P
r
o
x
y
.
j
a
v
a
:
152
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
b
i
n
d
i
n
g
.
M
a
p
p
e
r
P
r
o
x
y
.
i
n
v
o
k
e
(
M
a
p
p
e
r
P
r
o
x
y
.
j
a
v
a
:
85
)
c
o
m
.
s
u
n
.
p
r
o
x
y
.
PlainMethodInvoker.invoke(MapperProxy.java:152) org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) com.sun.proxy.
PlainMethodInvoker.invoke(MapperProxy.java:152)org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)com.sun.proxy.Proxy24.findAllByPage(Unknown Source)
edu.whut.service.impl.UserServiceImpl.findByPage(UserServiceImpl.java:109)
edu.whut.controller.UserHandler.findAllByPage(UserHandler.java:161)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
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:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
Root 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 ‘-5, 5’ at line 5
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
com.sun.proxy.
P
r
o
x
y
28.
e
x
e
c
u
t
e
(
U
n
k
n
o
w
n
S
o
u
r
c
e
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
e
x
e
c
u
t
o
r
.
s
t
a
t
e
m
e
n
t
.
P
r
e
p
a
r
e
d
S
t
a
t
e
m
e
n
t
H
a
n
d
l
e
r
.
q
u
e
r
y
(
P
r
e
p
a
r
e
d
S
t
a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t
s
.
D
e
f
a
u
l
t
S
q
l
S
e
s
s
i
o
n
.
s
e
l
e
c
t
L
i
s
t
(
D
e
f
a
u
l
t
S
q
l
S
e
s
s
i
o
n
.
j
a
v
a
:
147
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
s
e
s
s
i
o
n
.
d
e
f
a
u
l
t
s
.
D
e
f
a
u
l
t
S
q
l
S
e
s
s
i
o
n
.
s
e
l
e
c
t
L
i
s
t
(
D
e
f
a
u
l
t
S
q
l
S
e
s
s
i
o
n
.
j
a
v
a
:
140
)
s
u
n
.
r
e
f
l
e
c
t
.
N
a
t
i
v
e
M
e
t
h
o
d
A
c
c
e
s
s
o
r
I
m
p
l
.
i
n
v
o
k
e
0
(
N
a
t
i
v
e
M
e
t
h
o
d
)
s
u
n
.
r
e
f
l
e
c
t
.
N
a
t
i
v
e
M
e
t
h
o
d
A
c
c
e
s
s
o
r
I
m
p
l
.
i
n
v
o
k
e
(
N
a
t
i
v
e
M
e
t
h
o
d
A
c
c
e
s
s
o
r
I
m
p
l
.
j
a
v
a
:
62
)
s
u
n
.
r
e
f
l
e
c
t
.
D
e
l
e
g
a
t
i
n
g
M
e
t
h
o
d
A
c
c
e
s
s
o
r
I
m
p
l
.
i
n
v
o
k
e
(
D
e
l
e
g
a
t
i
n
g
M
e
t
h
o
d
A
c
c
e
s
s
o
r
I
m
p
l
.
j
a
v
a
:
43
)
j
a
v
a
.
l
a
n
g
.
r
e
f
l
e
c
t
.
M
e
t
h
o
d
.
i
n
v
o
k
e
(
M
e
t
h
o
d
.
j
a
v
a
:
498
)
o
r
g
.
m
y
b
a
t
i
s
.
s
p
r
i
n
g
.
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
Proxy28.execute(Unknown Source) org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.mybatis.spring.SqlSessionTemplate
Proxy28.execute(UnknownSource)org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.lang.reflect.Method.invoke(Method.java:498)org.mybatis.spring.SqlSessionTemplateSqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
com.sun.proxy.
P
r
o
x
y
12.
s
e
l
e
c
t
L
i
s
t
(
U
n
k
n
o
w
n
S
o
u
r
c
e
)
o
r
g
.
m
y
b
a
t
i
s
.
s
p
r
i
n
g
.
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
s
e
l
e
c
t
L
i
s
t
(
S
q
l
S
e
s
s
i
o
n
T
e
m
p
l
a
t
e
.
j
a
v
a
:
223
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
b
i
n
d
i
n
g
.
M
a
p
p
e
r
M
e
t
h
o
d
.
e
x
e
c
u
t
e
F
o
r
M
a
n
y
(
M
a
p
p
e
r
M
e
t
h
o
d
.
j
a
v
a
:
147
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
b
i
n
d
i
n
g
.
M
a
p
p
e
r
M
e
t
h
o
d
.
e
x
e
c
u
t
e
(
M
a
p
p
e
r
M
e
t
h
o
d
.
j
a
v
a
:
80
)
o
r
g
.
a
p
a
c
h
e
.
i
b
a
t
i
s
.
b
i
n
d
i
n
g
.
M
a
p
p
e
r
P
r
o
x
y
Proxy12.selectList(Unknown Source) org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223) org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) org.apache.ibatis.binding.MapperProxy
Proxy12.selectList(UnknownSource)org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)org.apache.ibatis.binding.MapperProxyPlainMethodInvoker.invoke(MapperProxy.java:152)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
com.sun.proxy.$Proxy24.findAllByPage(Unknown Source)
edu.whut.service.impl.UserServiceImpl.findByPage(UserServiceImpl.java:109)
edu.whut.controller.UserHandler.findAllByPage(UserHandler.java:161)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
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:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/8.5.39