首页 \ 问答 \ 如何从MyBatis Java调用存储过程?(How to call a stored procedure from MyBatis Java?)

如何从MyBatis Java调用存储过程?(How to call a stored procedure from MyBatis Java?)

我收到错误:

org.mybatis.spring.MyBatisSystemException:嵌套异常是org。 阿帕奇。 ibatis的。 exceptions.PersistenceException:

java.lang.IllegalArgumentException:映射语句集合不包含..的值。“

当我使用Java从mybatis调用存储过程时。

我使用PostgreSQL作为数据库和Spring MVC框架。 为此,我的DAO类调用存储过程是:

Orders orders=new Orders();

值以编程方式设置为可变顺序。

Integer insert= getSqlSession().insert("records",orders);**

我的mybatis文件如下所示:

<insert id="records" parameterType="Orders" statementType="CALLABLE">
 {call fn_records_tbl(#{rId,javaType=Integer,jdbcType=INTEGER,mode=IN},#{state,javaType=String,jdbcType=CHAR,mode=IN},#{uId,javaType=Integer,jdbcType=INTEGER,mode=IN},#{status,javaType=String,jdbcType=CHAR,mode=IN})}
</insert>

我的存储过程的语法是:

CREATE OR REPLACE FUNCTION fn_records_tbl(rId integer, state character,uId integer, status character)

RETURNS void AS

$BODY$
DECLARE

    -- my code
BEGIN

    -- my code
END

$BODY$

LANGUAGE plpgsql VOLATILE
COST 100;

ALTER FUNCTION fn_records_tbl(integer, character, integer, character)
OWNER TO mydba;

和我的实体类传递参数是:

 public class Orders implements Serializable {

  private static final long serialVersionUID = 267216928694677437L;
  private Integer uId;
  private Integer rId;
  private String status;
  private String state;

     // here are my setter and getter
 }

I am getting the error:

org.mybatis.spring.MyBatisSystemException: nested exception is org. apache. ibatis. exceptions.PersistenceException:

and

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for .."

when I call stored procedure from mybatis using Java.

I am using PostgreSQL as a database and a Spring MVC framework. For this, my DAO class calling the stored procedure is:

Orders orders=new Orders();

Values are set in orders variable programatically.

Integer insert= getSqlSession().insert("records",orders);**

My mybatis file looks like this:

<insert id="records" parameterType="Orders" statementType="CALLABLE">
 {call fn_records_tbl(#{rId,javaType=Integer,jdbcType=INTEGER,mode=IN},#{state,javaType=String,jdbcType=CHAR,mode=IN},#{uId,javaType=Integer,jdbcType=INTEGER,mode=IN},#{status,javaType=String,jdbcType=CHAR,mode=IN})}
</insert>

My stored procedure syntax is:

CREATE OR REPLACE FUNCTION fn_records_tbl(rId integer, state character,uId integer, status character)

RETURNS void AS

$BODY$
DECLARE

    -- my code
BEGIN

    -- my code
END

$BODY$

LANGUAGE plpgsql VOLATILE
COST 100;

ALTER FUNCTION fn_records_tbl(integer, character, integer, character)
OWNER TO mydba;

and my entity class for passing parameters is:

 public class Orders implements Serializable {

  private static final long serialVersionUID = 267216928694677437L;
  private Integer uId;
  private Integer rId;
  private String status;
  private String state;

     // here are my setter and getter
 }

原文:https://stackoverflow.com/questions/12257921
更新时间:2023-06-19 21:06

最满意答案

字符串结束后是否有可能有空格? 尝试打印它包围引号。


I caved.

$values = preg_replace("/,$/", "", $values);

If anyone knows what I was doing wrong, I'd love to hear it though. It's got me stumped.

相关问答

更多
  • 只有一个空间,还是所有这样的空间? 如果是第二个,则字符串已经有.strip()方法: >>> ' Hello '.strip() 'Hello' >>> ' Hello'.strip() 'Hello' >>> 'Bob has a cat'.strip() 'Bob has a cat' >>> ' Hello '.strip() # ALL spaces at ends removed 'Hello' 如果你只需要删除一个空格,你可以这样做: def strip_o ...
  • "Hello! world!".TrimEnd('!'); 阅读更多 编辑: 我在这种类型的问题中注意到,每个人都建议删除给定字符串的最后一个字符。 但这并不能完成Trim方法的定义。 修剪 - 从此实例的开头和结尾删除所有出现的空白字符。 MSDN剪裁 在这个定义下,从字符串中删除最后一个字符是不好的解决 所以如果我们要“从字符串修剪最后一个字符”,我们应该这样做 示例作为扩展方法: public static class MyExtensions { public static string Tr ...
  • 字符串结束后是否有可能有空格? 尝试打印它包围引号。 I caved. $values = preg_replace("/,$/", "", $values); If anyone knows what I was doing wrong, I'd love to hear it though. It's got me stumped.
  • 一个简单的是 R> gsub("^([A-Z]*)_.*", "\\1", "ABC_constantStuff_ABC_randomStuff") [1] "ABC" R> 其中所有字母都是第一个_ 。 另一个假设_是你的分隔符是 R> strsplit( "ABC_constantStuff_ABC_randomStuff", "_")[[1]][c(1,3)] [1] "ABC" "ABC" R> A simple one is R> gsub("^([A-Z]*)_.*", "\\1", " ...
  • 这是一个有用的习惯用法:要从字符串右侧删除特定字符之前的所有字符(包括该特殊字符),请使用以下命令: $trimmed = substr($str, 0, strrpos($str, ' ')); ......那是' '那个特殊的角色。 演示 但是,如果您不知道该字符是否存在,则首先检查sttrrpos的结果: $last_space_index = strrpos($str, ' '); $trimmed = $last_space_index !== false ? substr($str, 0, ...
  • 正如Screwtape所说,使用ENTRY很容易做到这一点。 如果您出于某种原因想要使用INDEX和搜索位置,您可以这样做。 R-INDEX将帮助您 - 从右到左而不是从左到右搜索字符串。 例如,如果您有多个与搜索字符串匹配的条目,则此示例将出现问题。 在这种情况下,它将返回最左边的匹配条目。 DEFINE VARIABLE cString AS CHARACTER NO-UNDO. DEFINE VARIABLE cSearch AS CHARACTER NO-UNDO. DEFINE VAR ...
  • 您可以使用下面的代码片段检查最后一个字符是否为数字: 例如: string value = "4+8-4*"; int outInt = 0; bool isLastCharNumeric = int.TryParse(value[value.Length - 1].ToString(), out outInt); if (!isLastCharNumeric) { //chop off the last char value = value.Remove(value.Length - 1; ...
  • 要仅保留字符串的前100个字符,请使用子字符串 : s = s.substring(0,100) 要搜索子字符串使用indexOf : s.indexOf("#key") To keep only the first 100 characters of a string use substring: s = s.substring(0,100) To search for a substring use indexOf: s.indexOf("#key")
  • 我们可以使用sub来匹配零或更多. 或空格并用空格替换( "" ) sub("(\\.| )*$", "", v1) #[1] "depresion" "tristeza" "nostalgia" "preocupacion" "enojo" #[6] "soledad" "frustracion" "desesperacion" #[9] "angustia" "desconocidos" 数据 v1 <- c("depresion","tr ...
  • Regex rg = new Regex(@"[01]?\d[/-][0123]?\d[/-]\d{2}"); Match m = rg.Match("Sat, 02/04/1708:00 PM"); Console.Write(m.ToString()); WORKING FIDDLE Regex rg = new Regex(@"[01]?\d[/-][0123]?\d[/-]\d{2}"); Match m = rg.Match("Sat, 02/04/1708:00 PM"); Cons ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。