mybatis 调用存储过程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis 调用存储过程相关的知识,希望对你有一定的参考价值。
A query was run and no Result Maps were found for the Mapped Statement 'MediumManager.proHello'. It's likely that neither a Result Type nor a Result Map was specified.
mybatis3.0 调用 存储过程 的时候,老是报这个错误,谁知道怎么回事啊,麻烦给解决一下
以下为错误信息
### Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'MediumManager.proHello'. It's likely that neither a Result Type nor a Result Map was specified.
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'MediumManager.proHello'. It's likely that neither a Result Type nor a Result Map was specified.
数据库是 人大金仓的 哪位使用过
有任何问题请私信我!
记得采纳哦!追问
在oracle数据库里面是正常的,现在在测试 人大金仓 就无法返回了,我只需要返回一个值就可以
追答我知道啊
你检查你的参数
追问代码
xml是这么写的
这么调用的
snValue是你要返回的参数(结果),但是你没指定它的resultType或resultMap。
我比较奇怪的是,snValue的mode是OUT,你为什么还param.put("snValue", "02")?
12mybatis调用执行存储过程
mybatis 调用执行存储过程
mysql 声明建立存储过程 删除 在mysql中调用
-- 声明定义存储过程
delimiter $$
create procedure delbook(id int)
begin
delete from book where book_id=id;
end$$
delimiter ;
-- 删除存储过程
drop procedure delbook;
-- 调用执行存储过程
call delbook(4);
select * from book;
mybatis 调用删除存储过程
-- 声明定义存储过程--------------------------------------------
delimiter $$
create procedure delbook(id int)
begin
delete from book where book_id=id;
end$$
delimiter ;
BookMapper.java 映射接口文件
public int delbook(int id);
BookMapper.xml 映射配置文件
<parameterMap id="pm" type="map">
<parameter property="id" javaType="int" mode="IN"/>
</parameterMap>
<update id="delbook" statementType="CALLABLE" parameterMap="pm">
{call delbook(?)}
</update>
程序调用
int i = bdao.delbook(3);
-- 声明一个插入数据的存储过程--------------------------------------------
delimiter $$
create procedure addbook(name varchar(20),price decimal(8,2))
begin
insert into book(book_name,book_price) values(name,price);
end$$
delimiter ;
-- 调用一下
call addbook(‘《java开发》‘,80);
BookMapper.java 映射接口
public int addBook(Map<String,Object> map);
BookMapper.xml 映射文件
注册映射文件的参数顺序
<parameterMap id="am" type="map">
<parameter property="name" javaType="String" mode="IN"/>
<parameter property="price" javaType="double" mode="IN"/>
</parameterMap>
<update id="addBook" statementType="CALLABLE" parameterMap="am">
{call addbook(?,?)}
</update>
程序调用方法
Map<String,Object> m = new HashMap<String,Object>();
m.put("name","《项目开发》");
m.put("price",28d);
int i = bdao.addBook(m);
System.out.println(i);
-- 声明定义存储过程--------------------------------------------
delimiter $$
create procedure showbook()
begin
select * from book;
end$$
delimiter ;
-- 调用存储
call showbook;
call showbook();
BookMapper.java
public List<Book> showbook();
BookMapper.xml
<resultMap id="mp" type="book">
<id column="book_id" property="id"/>
<result column="book_name" property="name"/>
<result column="book_price" property="price"/>
</resultMap>
<select id="showbook" statementType="CALLABLE" resultMap="mp">
{call showbook()}
</select>
程序代码
List<Book> bks = bdao.showbook();
System.out.println(bks.size());
for(Book b : bks){
System.out.println(b.getName());
}
-- 声明定义存储过程
delimiter $$
create procedure bookcc(out r int)
begin
select count(*) into r from book;
end$$
delimiter ;
call bookcc(@r);
select @r;
BookMapper.java
public void bookcc(Map<String,Object> map);
BookMapper.xml 文件
<select id="bookcc" statementType="CALLABLE">
{call bookcc(#{r,mode=OUT,jdbcType=INTEGER})}
</select>
程序代码调用
Map<String,Object> m = new HashMap<String,Object>();
bdao.bookcc(m);
System.out.println(m.get("r"));
别一种方式
BookMapper.java 映射接口
public void bookcc(Map<String,Object> map);
BookMapper.xml 映射配置文件
<parameterMap id="cm" type="map">
<parameter property="r" jdbcType="INTEGER" mode="OUT"/>
</parameterMap>
<select id="bookcc" statementType="CALLABLE" parameterMap="cm">
{call bookcc(?)}
</select>
程序代码为
Map<String,Object> m = new HashMap<String,Object>();
bdao.bookcc(m);
System.out.println(m.get("r"));
总程序测试代码如下:
package com;
import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by webrx on 2017-06-16.
*/
public class Demo {
protected SqlSessionFactory sf;
protected SqlSession ss;
protected BookMapper bdao;
@Before
public void init(){
try {
this.sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
this.ss = this.sf.openSession();
this.bdao = this.ss.getMapper(BookMapper.class);
} catch (IOException e) {
e.printStackTrace();
}
}
@After
public void close(){
this.ss.commit();
this.ss.close();
}
@Test
public void s1() throws SQLException {
Connection conn = this.ss.getConnection();
PreparedStatement pst = conn.prepareStatement("create database ddd");
pst.execute();
pst.close();
conn.close();
}
@Test
public void s2(){
//bdao.dropDb("ddd");
List<Map<String,Object>> dbs = bdao.showDbs();
for(Map<String,Object> map : dbs){
System.out.println(map.get("Database"));
}
}
@Test
public void s4(){
//int i = bdao.delbook(3);
//System.out.println(i);
//Map<String,Object> m = new HashMap<String,Object>();
//m.put("name","《项目开发》");
//m.put("price",28d);
//int i = bdao.addBook(m);
//System.out.println(i);
//List<Book> bks = bdao.showbook();
//System.out.println(bks.size());
//for(Book b : bks){
// System.out.println(b.getName());
//}
Map<String,Object> m = new HashMap<String,Object>();
bdao.bookcc(m);
System.out.println(m.get("r"));
}
@Test
public void s3(){
//bdao.dropDb("ddd");
List<String> dbs = bdao.showDbs2();
for(String n : dbs){
System.out.println(n);
}
}
}
以上是关于mybatis 调用存储过程的主要内容,如果未能解决你的问题,请参考以下文章