简体   繁体   中英

SimpleJDBCCall class parameter passing

I have a stored procedure in y db which is on MYSQL server. And when I try to call it, it gives the error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect number of arguments for PROCEDURE thu.productGetter; expected 2, got 0 at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:95) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1137) at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1173) at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:378) at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:363)

Java code is:

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(getJdbcTemplate())
                                    .withSchemaName("thu")
                                    .withProcedureName("productGetter");

    jdbcCall.addDeclaredParameter(new SqlParameter("maxPrice", Types.DOUBLE));
    jdbcCall.addDeclaredParameter(new SqlParameter("minPrice", Types.DOUBLE));

    Map<String, Object> params=new HashMap<String, Object>();
    params.put("maxPrice", maxPrice);
    params.put("minPrice", minPrice);


    jdbcCall.execute(params);

And the stored procedure db code is:

CREATE DEFINER=`root`@`localhost` PROCEDURE `productGetter`(IN maxPrice double,minPrice double)
BEGIN
        ...    
END$$

I have checked plenty of examples and could not find any solution for my problem.

Any ideas?

I've experienced the same issue after upgrading from mysql 5.1 connector to 6.0.6 and the way to solve is just to add : .withoutProcedureColumnMetaDataAccess() in this way :

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(getJdbcTemplate())
                                    .withSchemaName("thu")
                                    .withProcedureName("productGetter")
                                    .withoutProcedureColumnMetaDataAccess();

    jdbcCall.addDeclaredParameter(new SqlParameter("maxPrice", Types.DOUBLE));
    jdbcCall.addDeclaredParameter(new SqlParameter("minPrice", Types.DOUBLE));

    Map<String, Object> params=new HashMap<String, Object>();
    params.put("maxPrice", maxPrice);
    params.put("minPrice", minPrice);


    jdbcCall.execute(params);

关于丢失参数我也有同样的消息,但事实证明是模式名称错误

You could try MapSqlParamterSorce instead.

SimpleJdbcCall jdbcCall = new SimpleJdbcCall(getJdbcTemplate())
                                    .withSchemaName("thu")
                                    .withProcedureName("productGetter")
                                    .withoutProcedureColumnMetaDataAccess();

jdbcCall.addDeclaredParameter(new SqlParameter("maxPrice", Types.DOUBLE));
jdbcCall.addDeclaredParameter(new SqlParameter("minPrice", Types.DOUBLE));

MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("maxPrice", maxPrice);
source.addValue("minPrice", minPrice);

jdbcCall.execute(source);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM