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值的沒有