« | August 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 | 31 | | | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9688294 建立时间:2004年12月20日 |

| |
[java语言]spring JdbcTemplate 的queryForObject的若干问题 原创空间, 软件技术
邢红瑞 发表于 2005/11/12 15:33:39 |
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解决 |
|
回复:spring JdbcTemplate 的queryForObject的若干问题 原创空间, 软件技术
jiez(游客)发表评论于2012/11/24 22:46:32 |
|
» 1 »
|