org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
Exception in thread "main" org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:472)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:476)
at com.dao.IPeopleDaoImpl.getPeopleName(IPeopleDaoImpl.java:45)
at com.transaction.TransactionRun.run(TransactionRun.java:41)
at com.transaction.TransactionRun$$FastClassByCGLIB$$b8caec8a.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:692)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625)
at com.transaction.TransactionRun$$EnhancerByCGLIB$$2966f255.run(<generated>)
at com.Test.TestTransactionRun.main(TestTransactionRun.java:12)
这个查询的结果是null,没有数据所以就提示acual 为0.而查询的时候是期望查询有结果有记录,并且记录数是1. spring 这个查询中没有查询到数据就报错。解决方案就是要查询有结果,或者换一种查询方式。
我的出错行在这里,是我故意弄的:
System.out.println(peopleDao.getPeopleName(Integer.MAX_VALUE));//这个会出现异常,因为id为最大的int值的没有