求助java调用存储过程,报错:Parameter number 2 is not an OUT parameter

William_Wei007 2018-12-11 02:27:20
代码如下:

存储过程:
create PROCEDURE get_redbag_name(in p_id int ,out p_name VARCHAR(50))
begin
select name from qb_redbag_ticket where id = p_id into p_name ;
end ;



java mapper.xml调用方式:
<select id="findById" statementType="CALLABLE" parameterMap="homeVO">
{call get_redbag_name(?,?)}
</select>

<parameterMap type="map" id="homeVO">
<parameter property="p_id" jdbcType="INTEGER" mode="IN"/>
<parameter property="p_name" jdbcType="VARCHAR" mode="OUT"/>
</parameterMap>



dao层:

public  List<Map> findById(Map pram);



biz层:
public  void findById(Map pram){
setDb(0, MASTER);
redbagTicketDao.findById(pram);
}


service:
public void  findById(Map bo){
redbagTicketBiz.findById(bo);
System.out.println(bo.get("p_name"));
}


rest层:

@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/findById", method = RequestMethod.POST)
public Map queryRd(@RequestBody Map bo) {
log.debug("查询红包lname--" + JSON.toJSONString(bo));
try {
LinkedHashMap linkedHashMap = new LinkedHashMap();
redbagTicketService.findById(bo);
return super.returnSuccessInfo(linkedHashMap);
} catch (Exception e) {
log.error("异常信息- 查询红包name--系统异常:" + JSON.toJSONString(bo), e);
return super.returnFailtrueInfo(e);
}
}



test案例为:
@Test
public void findById(){

uri = "http://localhost:8080/front.onigiri/redbag/findById";

Map map = new HashMap<>();

map.put("p_id", 198898);
map.put("p_name", "");

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json; charset=utf-8"));
headers.set("Accept-Charset", "UTF-8");
HttpEntity entity = new HttpEntity(JSON.toJSONString(map),headers);
ResponseEntity response = restTemplate.exchange(uri,HttpMethod.POST, entity, Map.class);
LinkedHashMap responseMap = (LinkedHashMap)response.getBody();
System.out.print(responseMap);
assertTrue(true);

}



已排查信息:
1、数据库中有存储过程。
2、存储过程名称无错
3、已设置了权限:
 grant select,insert,update,delete  on fantuan.* to root@'localhost' identified by 'xxx';

grant execute on procedure fantuan.get_redbag_name to root@'localhost' identified by 'xxx';

grant select on mysql.proc to root@'localhost' identified by 'xxx';


FLUSH PRIVILEGES ;


4、链接数据库的位置也增加了 noAccessToProcedureBodies=true

以上方式都尝试了。依然错误。请各位知晓的朋友深处援助之手吧。谢谢啦
...全文
1038 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
William_Wei007 2018-12-13
  • 打赏
  • 举报
回复
引用 1 楼 bcsflilong 的回复:
希望给一个完整的操作信息 另外 配置文件中使用的用户直接登录mysql 然后 call get_redbag_name(11) 看看怎样
在此项目中,直接在mapper.xml文件中写SQL 是可以查询信息的。
William_Wei007 2018-12-13
  • 打赏
  • 举报
回复
引用 1 楼 bcsflilong 的回复:
希望给一个完整的操作信息 另外 配置文件中使用的用户直接登录mysql 然后 call get_redbag_name(11) 看看怎样
在客户端执行 set @name =''; call get_redbag_name(11,@name); select @name 是没问题的,因为有2个参数。 所以您这个 call get_redbag_name(11) 是不可以的。 会出现
[SQL]call  get_redbag_name(11);
[Err] 1318 - Incorrect number of arguments for PROCEDURE fantuan.get_redbag_name; expected 2, got 1
完整的信息? 没太理解。 这个就是springmvc项目,然后写了test案例,调用接口。
bcsflilong 2018-12-11
  • 打赏
  • 举报
回复
希望给一个完整的操作信息
另外 配置文件中使用的用户直接登录mysql 然后 call get_redbag_name(11) 看看怎样

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧