Professional Documents
Culture Documents
Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Making mybatis calls the stored procedure is very convenient, the following began to study
how Mybatis/Ibatis 2 Oracle stored procedure calls. First learn a simple output text
examples:
AS
begin
dbms_output.put_line(yes);
fly:='return something';
end proc_out;
parameterType="hashmap">
mode=OUT, jdbcType=VARCHAR})}]]>
</select>
not define the parameters of the stored procedure name remains the
params.put("yes", "china");
sqlSession.selectOne("test.testOutput", params);
System.out.println(result);
or return parameter>
jdbcType="VARCHAR"
mode="IN" />
jdbcType="VARCHAR"
mode="OUT" />
</parameterMap>
<![CDATA[{call proc_out(?,?)}]]>
</procedure>
SQLException {
mapIn.put("fly", "");
sqlMapper.queryForObject("test.testOutput",mapIn);
System.out.println(result);
Ps, Ibatis for each input to create a Map to specify the input and output parameters, with
Here making making began to use the table, first create table Emp:
-- Create table
JOB VARCHAR2(15),
MGR NUMBER,
HIREDATE DATE,
SALE NUMBER,
COMM NUMBER,
DEPTNO NUMBER
import java.util.Date;
@Override
hireDate.toLocaleString()
+ "]";
return empNo;
this.empNo = empNo;
}
return ename;
this.ename = ename;
return job;
this.job = job;
return mrg;
this.mrg = mrg;
return hireDate;
return sale;
this.sale = sale;
return comm;
this.comm = comm;
return depNo;
this.depNo = depNo;
}
Making a primary key first according to the Emp examples of records, stored procedure
corresponding to:
begin
end getEmpById;
</resultMap>
parameterType="map">
<![CDATA[
call getEmpById(#{userid,mode=IN,jdbcType=DECIMAL},
#{emp,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=e
nameMap})
]]>
</update>
not define the parameters of the stored procedure name remains the
params.put("userid", 7769);
sqlSession.selectOne("test.selectEmpById", params);
System.out.println(list.size() + "---" +
list.get(0).toString());
jdbcType="NUMBER"
mode="IN" />
</parameterMap>
resultClass="bean.EmpBean">
<![CDATA[{call getEmpById(?,?)}]]>
</procedure>
Making Ibatis test method:
SQLException {
t.put("userid",7782L);
List<EmpBean> list =
sqlMapper.queryForList("test.selectEmpById",t);
System.out.println(list.size()+"----
="+list.get(0).toString());
Making the following learning to use stored procedures for common CRUD operations, first
e_name in varchar2,
e_job in varchar2,
e_mgr in long,
e_date in date,
e_sale in long,
e_comm in long,
e_depno in long,
begin
VALUES
commit;
EXCEPTION
end addEmp;
{call
addEmp(#{empNo},#{ename},#{job},#{mrg},#{hireDate},#{sale},#{co
mm},#{depNo},#{message,
mode=OUT,javaType=string,jdbcType=VARCHAR})}
</insert>
params.put("empNo", 123);
params.put("ename", "testadd");
params.put("job", "testjob");
params.put("mrg", 123);
params.put("sale", 8000);
params.put("comm", 1);
params.put("depNo", 20);
sqlSession.selectOne("test.addEmp", params);
System.out.println(result);
}
Making configuration for Ibatis:
javaType="java.lang.Long"
mode="IN" />
javaType="java.lang.String"
mode="IN" />
javaType="java.lang.String"
mode="IN" />
javaType="java.lang.Long"
mode="IN" />
javaType="java.util.Date"
mode="IN" />
javaType="java.lang.Long"
mode="IN" />
javaType="java.lang.Long"
mode="IN" />
javaType="java.lang.Long"
mode="IN" />
javaType="java.lang.String"
mode="OUT" />
</parameterMap>
<![CDATA[{call addEmp(?,?,?,?,?,?,?,?,?)}]]>
</procedure>
params.put("empNo", 124L);
params.put("ename", "testadd");
params.put("job", "testjob");
params.put("mrg", 124L);
params.put("sale", 8000L);
params.put("comm", 2L);
params.put("depNo", 20L);
params.put("message","");
sqlMapper.update("test.addEmp",params);
System.out.println(params.get("message"));
e_name in varchar2,
e_job in varchar2,
e_mgr in long,
e_date in date,
e_sale in long,
e_comm in long,
e_depno in long,
begin
update emp u
JOB = e_job,
MGR = e_mgr,
HIREDATE = e_date,
SALE=e_sale,
COMM=e_comm,
DEPTNO=e_depno
commit;
EXCEPTION
end updateEmp;
{call
updateEmp(#{empNo},#{ename},#{job},#{mrg},#{hireDate},#{sale},#
{comm},#{depNo},#{message,
mode=OUT,javaType=string,jdbcType=VARCHAR})}
</update>
params.put("empNo", 123);
params.put("ename", "testupdate");
params.put("job", "testjob2");
params.put("mrg", 123);
params.put("sale", 8500);
params.put("comm", 1);
params.put("depNo", 20);
sqlSession.selectOne("test.updateEmp", params);
System.out.println(result);
<![CDATA[{call updateEmp(?,?,?,?,?,?,?,?,?)}]]>
</procedure>
SQLException{
params.put("empNo", 124L);
params.put("ename", "testupdate");
params.put("job", "testjob");
params.put("mrg", 125L);
params.put("sale", 8500L);
params.put("comm", 3L);
params.put("depNo", 20L);
params.put("message","");
sqlMapper.update("test.updateEmp",params);
System.out.println(params.get("message"));
end JUV;
as
begin
end getAllEmp;
<![CDATA[{call
getAllEmp(#{empList,mode=OUT,javaType=java.sql.ResultSet,jdbcType=CURS
OR,resultMap=enameMap})}]]>
</select>
params.get("empList");
System.out.println(empBean);
resultClass="bean.EmpBean">
<![CDATA[{call getAllEmp(?)}]]>
</procedure>
SQLException {
List<EmpBean> list =
sqlMapper.queryForList("test.getEmps");
System.out.println(empBean);
varchar2) is
begin
commit;
EXCEPTION
end delEmp;
{call delEmp(#{id},#{message,
mode=OUT,javaType=string,jdbcType=VARCHAR})}
</delete>
params.put("id", 7844);
sqlSession.selectOne("test.delEmp", params);
System.out.println(result);
javaType="java.lang.Long"
mode="IN" />
<parameter property="message" jdbcType="VARCHAR"
javaType="java.lang.String"
mode="OUT" />
</parameterMap>
<![CDATA[{call delEmp(?,?)}]]>
</procedure>
params.put("empNo", 124L);
params.put("message","");
sqlMapper.update("test.delEmp",params);
System.out.println(params.get("message"));
Making over.
Making making in the testing process, Find Mybatis in the Number type record does not
exist when the automatic return 0, Ibatis error, Don't know Is it right? Ibatis configuration
error, In addition, Ibatis personal feeling of calling a stored procedure should have more
concise, Welcome advice, Write not place, Please forgive me, In addition, The examples in
this article on the net also to, Simply put them together.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from
Latest Questions
is there any criteria for garmin map update?
Have you problem printer in error state?
Assignment Help
Get Best 300 savage ammo
Best CDR Help Service Provider Company in All Country
Solution