spring - Spring JdbcTemplate:PreparedStatement的ResultSet中count(*)的返回值类型
问题描述
Spring JdbcTemplate的Prepared Statement的ResultSet中count(*)的返回值类型是什么?
String query = "select count(*) as ROW_COUNT from table1";
List<Map<String, Object>> list = executePreparedStatement(query);
Iterator<Map<String, Object>> iter = list.iterator();
if (iter.hasNext()) {
Map<String, Object> lom = iter.next();
return (((Long) lom.get("ROW_COUNT"))).intValue();
}
这是否取决于 JDBC 驱动程序/和或数据库?
例如,在 DB2 中,返回值类型是 Integer,但在 PostgreSQL 中是 Long。
为什么这不一样?
解决方案
Different vendors have different implementations.
Sometimes even a single vendor can have different implementations.
You need to code accordingly.
Db2 for Linux/Unix/Windows, Db2 for i-Series, Db2 for Z/OS, all return a large integer from the COUNT function.
Additionally Db2 for i can return DECIMAL(15,0) from the count function if the table is distributed.
There's also the COUNT_BIG function in Db2 which returns DECIMAL(31,0).
推荐阅读
- reactjs - 如何使用 React Router 将旧的哈希链接重定向到新链接?
- python - 有没有办法将带有某些值的 python 字典字符串转换为 python 命令?
- python - 有没有办法打印一个字符串并防止它在随机字符串生成器中重新打印?
- php - 属于很多不附加数据 Laravel
- java - Red Hat Fuse 7.2 单元测试产生一个令人困惑的 RuntimeException - 即“放弃等待来自 bundle 的 BlueprintContainer”
- laravel - 共享主机上的 Laravel 存储符号链接
- ios - LoadFileUrl 和 LoadHtmlString 未加载本地文档资源
- git - 推送被拒绝:在提交消息中找不到 JIRA 问题。分支名称(预接收挂钩被拒绝)错误:未能将一些参考推送到 http://@bitbucket.com
- strapi - 以管理员身份登录后,如何在我的前端页面上列出所有用户?
- react-native - React Native,将导航传递给无状态平面列表组件