存储过程调用(namedparameterjdbctemplate)
Stored procedures call (namedparameterjdbctemplate)
我正在尝试使用 jdbc 调用存储过程。我的连接是通过 namedParameterJdbcTemplate 传递的,这就是我必须用来调用它的方式,但是当我尝试这样做时:
public void storedProcedure(long fileId, String Action) {
String sql = "call procedureName(?)";
try {
namedParameterJdbcTemplate.update(sql, Long.valueOf(fileId) );
} catch (Exception e) {
logger.error("Error while running stored procedure {}", sql, e);
}
}
我收到以下错误:
Cannot resolve method 'update(java.lang.String, java.lang.Long)'
我尝试查看但无法正常工作的来源:
- https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/jdbc.html
- https://lalitjc.wordpress.com/2013/07/02/different-ways-of-calling-stored-procedure-using-spring/
- https://www.logicbig.com/tutorials/spring-framework/spring-data-access-with-jdbc/spring-call-stored-procedure.html
他们中的大多数人从一开始就创建了一个连接,但我已经有了它 (namedParameterJdbcTemplate),还有一些正在使用我不需要的数据源,因为我已经有了连接。
如何使用 namedParameterJdbcTemplate 进行调用?
谢谢
你的语法看起来不对。使用 NamedParameterJdbcTemplate 调用更新时,需要使用这两个方法签名中的任何一个来调用该方法。
update(String sql, Map<String,?> paramMap)
或
update(String sql, SqlParameterSource paramSource)
这里有更多示例 - https://netjs.blogspot.com/2016/11/insert-update-using-namedparameterjdbctemplate-spring.html
这是它的工作原理:
final String sql = "call procedureName (:variable)";
SqlParameterSource namedParameters = new MapSqlParameterSource("variable", variable);
try {
namedParameterJdbcTemplate.update(sql, namedParameters);
} catch (Exception e){
...
}
我正在尝试使用 jdbc 调用存储过程。我的连接是通过 namedParameterJdbcTemplate 传递的,这就是我必须用来调用它的方式,但是当我尝试这样做时:
public void storedProcedure(long fileId, String Action) {
String sql = "call procedureName(?)";
try {
namedParameterJdbcTemplate.update(sql, Long.valueOf(fileId) );
} catch (Exception e) {
logger.error("Error while running stored procedure {}", sql, e);
}
}
我收到以下错误:
Cannot resolve method 'update(java.lang.String, java.lang.Long)'
我尝试查看但无法正常工作的来源:
- https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/jdbc.html
- https://lalitjc.wordpress.com/2013/07/02/different-ways-of-calling-stored-procedure-using-spring/
- https://www.logicbig.com/tutorials/spring-framework/spring-data-access-with-jdbc/spring-call-stored-procedure.html
他们中的大多数人从一开始就创建了一个连接,但我已经有了它 (namedParameterJdbcTemplate),还有一些正在使用我不需要的数据源,因为我已经有了连接。
如何使用 namedParameterJdbcTemplate 进行调用?
谢谢
你的语法看起来不对。使用 NamedParameterJdbcTemplate 调用更新时,需要使用这两个方法签名中的任何一个来调用该方法。
update(String sql, Map<String,?> paramMap)
或
update(String sql, SqlParameterSource paramSource)
这里有更多示例 - https://netjs.blogspot.com/2016/11/insert-update-using-namedparameterjdbctemplate-spring.html
这是它的工作原理:
final String sql = "call procedureName (:variable)";
SqlParameterSource namedParameters = new MapSqlParameterSource("variable", variable);
try {
namedParameterJdbcTemplate.update(sql, namedParameters);
} catch (Exception e){
...
}