代替的方法为queryForObject(String sql, Object[] args, Class<T> requiredType)。



  需要返回的是什么类型,就在第三个参数写什么类型。比如int类型就写Integer.class,

                                                                                                  long类型就写Long.class.


  1 String sqlStr = "select count(*) from t_user where user_name=? and password=?";
  2  int count =  jdbcTemplate.queryForObject(sqlStr,new java.lang.Object[]{userName,password},Integer.class);



下面这种写法报错,必须传入完整包名:

  1 String sqlStr = "select count(*) from t_user where user_name=? and password=?";
  2 
  3       return  jdbcTemplate.queryForObject(sqlStr,new Object[]{userName,password},Integer.class);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2021-08-30
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-09
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-02-01
相关资源
相似解决方案