---
title: "空集报异常处理方法"
author: "jackleechina"
date: "2012-07-03T14:14:33Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-07-03T14:14:57Z"
id: 1575646
url: "https://jackleechina.iteye.com/blog/1575646"
---

利用spring 的getJdbcTemplate().queryForMap如果返回空集，就会报 
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0 的异常，解决办法就是捕捉这个异常然后返回null即可。 


```java
try{   
     return getJdbcTemplate().queryForMap("select s.fb,s.pb,s.tu,s.qt,s.fbc,s.pbc,s.tt,s.ft,s.lt from gbc$view_user s where s.ud = ? and ad= ?", new Object[]{ud,ad});   
}catch (EmptyResultDataAccessException e) {   
     return null;   
}  
```


摘自：<http://chembo.iteye.com/blog/1052840>