|
天堂之光 人间希望
你我共同品味
JAVA的浓香.
Linux的清芬. |
« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
链接 |
联系我
msn:zhanglincon@hotmail.com |
Blog信息 |
blog名称: 日志总数:99 评论数量:281 留言数量:4 访问次数:810314 建立时间:2005年11月17日 |

| |
Incorrect result size: expected 1, actual 0错误以及解决方法 文章收藏, 软件技术
zhanglincon 发表于 2008/2/27 16:56:44 |
spring的javadoc上讲getObject(String, Object[], Class) will return NULL if the result of the query is NUL这里有0行和nullresult的区别0行: select salary from user where 1 = 2null result: select max(salary) from user where 1 = 2 返回就是null0行一定抛出IncorrectResultSizeDataAccessException异常原因如下ResultSetMetaData rsmd = rs.getMetaData();int nrOfColumns = rsmd.getColumnCount();这里返回ResultSet的列数 if (nrOfColumns != 1) { throw new IncorrectResultSizeDataAccessException( "Expected single column but found " + nrOfColumns, 1, nrOfColumns); }0行,多于1行,就抛异常了 最好还是用QueryForList,返回的list的size为0,就是0行 还有oracle 10g的问题,jdbc驱动版本10.1.0.20getObject返回一个日期类型为java.util.Date但是这个日期只有年-月-日,没有时-分-秒,因为10g对于DATE类型的列,getObject().getClass().getName()得到 java.sql.DateSystem.out.println(rs.getObject("date_created") + " " + rs.getObject("date_created").getClass());得到 2005-10-06 class java.sql.Date要得到全部日期,必须使用oracle.sql.TIMESTAMP但是使用queryForObject("sql", Timestamp.class) 得到org.springframework.dao.TypeMismatchDataAccessException异常java.sql.Timestamp] and could not be converted to required type [java.sql.Timestamp] 很是莫名其妙只好使用java -Doracle.jdbc.V8Compatibility="true" MyApp解决 |
|
回复:Incorrect result size: expected 1, actual 0错误以及解决方法 文章收藏, 软件技术
12321321(游客)发表评论于2010/7/30 10:16:11 |
|
» 1 »
|