前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >new ScalarHandler()-->返回值为long,不能用int接收!!!

new ScalarHandler()-->返回值为long,不能用int接收!!!

作者头像
发布2020-10-23 10:45:48
1.5K0
发布2020-10-23 10:45:48
举报
文章被收录于专栏:后端JavaEE后端JavaEE

1.用int接收,错误如下:

代码语言:javascript
复制
public class ProductDaoImpl implements ProductDao {
    QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
    //根据tid返回每个种类的总数
    @Override
    public int findCountProduct(int tid) throws SQLException {
        String sql = "select count(1) from product where t_id = ?";
        int i = (int)qr.query(sql, new ScalarHandler(), tid);
        return i;
    }
}
在这里插入图片描述
在这里插入图片描述

2.按照错误提示:new ScalarHandler()需要使用long接收。修改后如下:

代码语言:javascript
复制
public class MyTest {
    public static void main(String[] args) throws Exception {
        ProductDao productDao = new ProductDaoImpl();
        System.out.println(productDao.findCountProduct(1));
    }
}
在这里插入图片描述
在这里插入图片描述

3.错误原因:

qr.query()返回object类型 ,先转成 ScalarHandler的Long类型 然后 在转为 int类型,之前我直接就转成int类型所以就GG了呱~。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-09-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.用int接收,错误如下:
  • 2.按照错误提示:new ScalarHandler()需要使用long接收。修改后如下:
  • 3.错误原因:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档