mybatis call stored procedure
The syntax for calling a stored procedure in JDBC is as follows. Note that square brackets indicate that the content between them is optional; the square brackets themselves are not part of the syntax.
{call procedure_name[(?, ?, ...)]}
The syntax for a procedure that returns a result parameter is:
{? = call procedure_name[(?, ?, ...)]}
a stored procedure with no parameters The syntax is similar:
{call procedure name}
XML configuration with return value
<select id="getReturnCount" parameterType="java.util.Map" statementType="CALLABLE"> <![CDATA[ {#{cityCount,mode=OUT,jdbcType=INTEGER}=call dbo.p_logic_test_web( #{cityId,mode=IN,jdbcType=INTEGER} )} ]]> </select>
The returned result is a Map, which takes the value directly from the key= cityCount in the map
non-XML configuration
/** * Execute pre-segmented stored procedure * * @param allocateDate: pre-allocate date, such as: 2017-01-01 00:00:00 * @param planMoney: plan share amount: unit is cent * @throws Exception * @return: actual share amount */ public void execPreAllocateProcedure(String allocateDate, int planMoney, Integer linkId) throws Exception { String call = "{call p_logic_shortcut_preallocate_money_day_web(?,?,?)}"; CallableStatement callableStatement=null; Connection conn = getDataSource().getConnection(); java.sql.Date date = new java.sql.Date(DateUtil.convertStringToDate(allocateDate, "yyyy-MM-dd HH:mm:ss").getTime()); try { callableStatement = conn.prepareCall(call); callableStatement.setDate(1, date); callableStatement.setInt(2, planMoney); callableStatement.setInt(3, linkId); callableStatement.execute(); } catch (Exception e) { throw new IspRollBackException("Error calling stored procedure: " + e.getMessage()); } finally { callableStatement.close(); conn.close(); } }