mybatis调用存储过程(oracle)
来源:互联网 发布:java游戏破解版网站 编辑:程序博客网 时间:2024/06/16 07:48
存储过程:
create or replace procedure pro_add(p1 in number,p2 in number,p3 out number)
as
begin
p3:=p1+p2;
end;
函数:
create or replace function fun_add(p1 in number,p2 in number)
return number
as
begin
return p1+p2;
Mapper.xml:
<!-- jdbc调用存储过程语法
{call 存储过程名(?,?)}
函数语法
{?=call 函数名(?,?)} -->
<mapper namespace="proc">
<!-- 存储过程 -->
<select id="call_pro_add" resultType="java.util.Map" statementType="CALLABLE">
{call pro_add(
#{p1,mode=IN,jdbcType=NUMERIC},
#{p2,mode=IN,jdbcType=NUMERIC},
#{result,mode=OUT,jdbcType=NUMERIC})}
</select>
<!-- 函数-->
<select id="call_fun_add" resultType="java.util.Map" statementType="CALLABLE">
{#{result,mode=OUT,jdbcType=NUMERIC}=call fun_add(
#{p1,mode=IN,jdbcType=NUMERIC},
#{p2,mode=IN,jdbcType=NUMERIC})
}
</select>
</mapper>
测试方法:
private SqlSession getSession() throws IOException {
// mybatis核心配置文件路径
String resource = "cn/et/lesson2/preduce/mybatis.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
// 工厂类
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(inputStream);
// session操作的是指向sql语句的一个唯一标识符
SqlSession openSession = sqlSessionFactory.openSession();
return openSession;
}
@Test
public void testProcInterface() throws IOException{
SqlSession session =getSession();
Map map=new HashMap();
map.put("p1", 1111);
map.put("p2", 1212);
map.put("result", 0);
session.selectOne("proc.call_pro_add",map);
System.out.println(map.get("result"));
}
@Test
public void testFunInterface() throws IOException{
SqlSession session =getSession();
Map map=new HashMap<String, Integer>();
map.put("p1", 1111);
map.put("p2", 1212);
map.put("result", 0);
session.selectOne("proc.call_fun_add",map);
System.out.println(map.get("result"));
}
create or replace procedure pro_add(p1 in number,p2 in number,p3 out number)
as
begin
p3:=p1+p2;
end;
函数:
create or replace function fun_add(p1 in number,p2 in number)
return number
as
begin
return p1+p2;
end;
Mapper.xml:
<!-- jdbc调用存储过程语法
{call 存储过程名(?,?)}
函数语法
{?=call 函数名(?,?)} -->
<mapper namespace="proc">
<!-- 存储过程 -->
<select id="call_pro_add" resultType="java.util.Map" statementType="CALLABLE">
{call pro_add(
#{p1,mode=IN,jdbcType=NUMERIC},
#{p2,mode=IN,jdbcType=NUMERIC},
#{result,mode=OUT,jdbcType=NUMERIC})}
</select>
<!-- 函数-->
<select id="call_fun_add" resultType="java.util.Map" statementType="CALLABLE">
{#{result,mode=OUT,jdbcType=NUMERIC}=call fun_add(
#{p1,mode=IN,jdbcType=NUMERIC},
#{p2,mode=IN,jdbcType=NUMERIC})
}
</select>
</mapper>
测试方法:
private SqlSession getSession() throws IOException {
// mybatis核心配置文件路径
String resource = "cn/et/lesson2/preduce/mybatis.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
// 工厂类
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(inputStream);
// session操作的是指向sql语句的一个唯一标识符
SqlSession openSession = sqlSessionFactory.openSession();
return openSession;
}
@Test
public void testProcInterface() throws IOException{
SqlSession session =getSession();
Map map=new HashMap();
map.put("p1", 1111);
map.put("p2", 1212);
map.put("result", 0);
session.selectOne("proc.call_pro_add",map);
System.out.println(map.get("result"));
}
@Test
public void testFunInterface() throws IOException{
SqlSession session =getSession();
Map map=new HashMap<String, Integer>();
map.put("p1", 1111);
map.put("p2", 1212);
map.put("result", 0);
session.selectOne("proc.call_fun_add",map);
System.out.println(map.get("result"));
}
阅读全文
0 0
- mybatis调用存储过程(oracle)
- MYBATIS调用oracle存储过程
- mybatis调用oracle存储过程
- MyBatis调用Oracle存储过程
- Mybatis调用oracle 存储过程
- mybatis调用ORACLE存储过程
- Mybatis 调用存储过过程(oracle 数据库)
- mybatis调用oracle存储过程 返回sys_refcursor
- mybatis 调用oracle存储过程 含输入输出
- Mybatis调用Oracle带包存储过程
- Mybatis调用Oracle带包存储过程
- 在 MyBatis 中调用Oracle存储过程
- MyBatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- mybatis调用存储过程
- Mybatis调用存储过程
- js 实现用window.print()打印页面中的部分内容,局部打印
- 素数
- 为selenium配置webdriver
- 数据结构 算法、线性表、顺序表
- 库函数strcmp的实现
- mybatis调用存储过程(oracle)
- poj2456Aggressive cows(二分搜索最小化最大值)
- 基本的JSP中调用Ajax与Servlet进行数据交互
- 通过MailServer和Foxmail搭建本地邮件服务器及实现本地邮箱账号收发邮件
- ubuntu下打开matlab
- Ubuntu下deb包的安装方法
- 母函数(生成函数)学习
- java笔记
- Tensorflow实例之使用LSTM预测股票每日最高价(二)