ibatis xml 文件
<parameterMap id="CommandSelectById" class="java.util.Map">
<parameter property="result" javaType="java.lang.String" jdbcType="VARCHAR" mode="OUT" />
</parameterMap>
<procedure id="Command_selectById" parameterMap="CommandSelectById">
{ ? = call truleadmin.proc_test(?) }
</procedure>
-----------------------------------------------
SQL 存储过程
create procedure proc_test @chr_id varchar(50)
as
declare @ftown varchar(30)
declare @fvillage varchar(30)
declare @newfid varchar(50)
select @fvillage=fvillage,@ftown=ftown from Hyjx_FoodDB..TdBase_Sp where chr_id=@chr_id
if(len(@fvillage)=10)
select @newfid=substring(@fvillage,1,6)+'0'+substring(@fvillage,7,2)+'0'+substring(@fvillage,9,len(@fvillage))
else
select @newfid=substring(@ftown,1,6)+'0'+substring(@ftown,7,len(@ftown))
select @newfid
go
需带一个(ID)varchar 类型的参数执行存储过程
-----------------------------------------------
java实现方法
public String changeEnt(Map map)
{
this.getSqlMapClientTemplate().queryForList("Command_selectById", map);
String num = (String)map.get("result");
return num;
}
现在不知道实现过程。 上面参数是Map 类型的, 下面调用怎么办?
-----------------------------------------------
java调用
this.regentup.changeEnt("000B9F2F9D994B14A0F83C00C1DE5E70");
2 个解决方案
#1
这是我的一个项目中的例子,可以参考一下
ibatis xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Link">
<parameterMap id="LinkMap" class="java.util.Map">
<parameter property="ip" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="port" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="aid" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="zid" javaType="String" jdbcType="STRING" mode="IN"/>
</parameterMap>
<procedure id="SaveLink" parameterMap="LinkMap">
<![CDATA[
{ call save_link(?, ?, ?, ?) }
]]>
</procedure>
</sqlMap>
java实现方法
public boolean AddCCLInk(
String ip,
String port,
String aid,
String zid){
boolean i = false;
try{
HashMap localHashMap = new HashMap(2);
localHashMap.put("ip", ip);
localHashMap.put("port", port);
localHashMap.put("aid", aid);
localHashMap.put("zid", zid);
this.sqlMapClient.queryForObject("SaveLink", localHashMap);
i = true;
}catch (Exception e) {
e.printStackTrace();
logger.error("保存原始VCC数据发生异常", e);
}
return i;
}
ibatis xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Link">
<parameterMap id="LinkMap" class="java.util.Map">
<parameter property="ip" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="port" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="aid" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="zid" javaType="String" jdbcType="STRING" mode="IN"/>
</parameterMap>
<procedure id="SaveLink" parameterMap="LinkMap">
<![CDATA[
{ call save_link(?, ?, ?, ?) }
]]>
</procedure>
</sqlMap>
java实现方法
public boolean AddCCLInk(
String ip,
String port,
String aid,
String zid){
boolean i = false;
try{
HashMap localHashMap = new HashMap(2);
localHashMap.put("ip", ip);
localHashMap.put("port", port);
localHashMap.put("aid", aid);
localHashMap.put("zid", zid);
this.sqlMapClient.queryForObject("SaveLink", localHashMap);
i = true;
}catch (Exception e) {
e.printStackTrace();
logger.error("保存原始VCC数据发生异常", e);
}
return i;
}
#2
虽然已经解决,但还是非常感谢!
#1
这是我的一个项目中的例子,可以参考一下
ibatis xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Link">
<parameterMap id="LinkMap" class="java.util.Map">
<parameter property="ip" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="port" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="aid" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="zid" javaType="String" jdbcType="STRING" mode="IN"/>
</parameterMap>
<procedure id="SaveLink" parameterMap="LinkMap">
<![CDATA[
{ call save_link(?, ?, ?, ?) }
]]>
</procedure>
</sqlMap>
java实现方法
public boolean AddCCLInk(
String ip,
String port,
String aid,
String zid){
boolean i = false;
try{
HashMap localHashMap = new HashMap(2);
localHashMap.put("ip", ip);
localHashMap.put("port", port);
localHashMap.put("aid", aid);
localHashMap.put("zid", zid);
this.sqlMapClient.queryForObject("SaveLink", localHashMap);
i = true;
}catch (Exception e) {
e.printStackTrace();
logger.error("保存原始VCC数据发生异常", e);
}
return i;
}
ibatis xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Link">
<parameterMap id="LinkMap" class="java.util.Map">
<parameter property="ip" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="port" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="aid" javaType="String" jdbcType="STRING" mode="IN"/>
<parameter property="zid" javaType="String" jdbcType="STRING" mode="IN"/>
</parameterMap>
<procedure id="SaveLink" parameterMap="LinkMap">
<![CDATA[
{ call save_link(?, ?, ?, ?) }
]]>
</procedure>
</sqlMap>
java实现方法
public boolean AddCCLInk(
String ip,
String port,
String aid,
String zid){
boolean i = false;
try{
HashMap localHashMap = new HashMap(2);
localHashMap.put("ip", ip);
localHashMap.put("port", port);
localHashMap.put("aid", aid);
localHashMap.put("zid", zid);
this.sqlMapClient.queryForObject("SaveLink", localHashMap);
i = true;
}catch (Exception e) {
e.printStackTrace();
logger.error("保存原始VCC数据发生异常", e);
}
return i;
}
#2
虽然已经解决,但还是非常感谢!