gpt4 book ai didi

java - 使用 JdbcTemplate.update() 执行存储过程是一个好习惯吗?

转载 作者:太空宇宙 更新时间:2023-11-04 12:04:38 25 4
gpt4 key购买 nike

目前我正在使用 JdbcTemplate.update() 方法来执行一个存储过程,该过程基本上更新并插入一些记录,并且它不返回任何东西。但我不确定使用 update() 方法执行存储过程是否是一个好习惯。使用该方法有什么缺点吗?或者我必须使用 execute() 方法吗?我试图避免实现execute(),因为它需要在我的应用程序中进行大量代码更改。

代码:

jdbcTemplate.update("call test_stored_proc(? , ?)", new Long[] {
userId, statusId });

最佳答案

您可以使用任何您想要的方式。 execute 是一种通用 API,可以运行任何内容,并让您知道它返回什么样的结果(结果集或受影响的行数)。 update 是一个特殊版本,适用于返回受影响的行或根本不返回任何内容的查询。

JdbcTemplate 将查询最终委托(delegate)给 java.sql.Statement

来自java.sql.Statement Javadoc :

executeUpdate(String sql): Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

execute(String sql): Executes the given SQL statement, which may return multiple results.

关于java - 使用 JdbcTemplate.update() 执行存储过程是一个好习惯吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com