1private Long findByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
4 activityId);
5 return timesViewed;
6}复制
1public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
2 throws DataAccessException {
3
4 List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
5 return DataAccessUtils.nullableSingleResult(results);
6}复制
1public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
2 if (CollectionUtils.isEmpty(results)) {
3 throw new EmptyResultDataAccessException(1);
4 } else if (results.size() > 1) {
5 throw new IncorrectResultSizeDataAccessException(1, results.size());
6 } else {
7 return results.iterator().next();
8 }
9}复制
1private Long queryByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = null;
4 try {
5 timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
6 activityId);
7 }
8 catch (EmptyResultDataAccessException ignored) {
9 }
10 return timesViewed;
11}复制
1private Long queryByActivityId(String activityId) {
2 String selectSql = "select times_viewed from activity_stats where activity_id = ?";
3 Long timesViewed = null;
4 try {
5 timesViewed = this.jdbcTemplate.queryForObject(selectSql, Long.class,
6 activityId);
7 }
8 catch (IncorrectResultSizeDataAccessException ignored) {
9 }
10 return timesViewed;
11}复制
文章转载自rookiedev,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
1224次阅读
2025-04-27 16:53:22
2025年4月国产数据库中标情况一览:4个千万元级项目,GaussDB与OceanBase大放异彩!
通讯员
690次阅读
2025-04-30 15:24:06
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
576次阅读
2025-04-14 09:40:20
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
496次阅读
2025-04-17 17:02:24
一页概览:Oracle GoldenGate
甲骨文云技术
472次阅读
2025-04-30 12:17:56
GoldenDB数据库v7.2焕新发布,助力全行业数据库平滑替代
GoldenDB分布式数据库
466次阅读
2025-04-30 12:17:50
优炫数据库成功入围新疆维吾尔自治区行政事业单位数据库2025年框架协议采购!
优炫软件
356次阅读
2025-04-18 10:01:22
国产数据库图谱又上新|82篇精选内容全览达梦数据库
墨天轮编辑部
269次阅读
2025-04-23 12:04:21
MySQL 30 周年庆!MySQL 8.4 认证免费考!这次是认真的。。。
数据库运维之道
249次阅读
2025-04-28 11:01:25
给准备学习国产数据库的朋友几点建议
白鳝的洞穴
237次阅读
2025-05-07 10:06:14