Updates
Hint
This article is generated by AI translation.
Execute SQL statements with no result set, such as INSERT, UPDATE, DELETE, or DDL.
info
- dbVisitor supports several argument-binding styles. Examples below use the most common ones: no arguments, positional arguments, and named arguments.
- See Arguments for the full feature set.
Usage
- Run DDL
int res = jdbc.executeUpdate("create table user_back(id bigint, name varchar(120));"); - Run INSERT / UPDATE / DELETE
No arguments
int res = jdbc.executeUpdate("insert into users (id, name) values(2, 'Alice')");Positional argumentsObject[] args = new Object[] { 2, "Alice" };
int res = jdbc.executeUpdate("insert into users (id, name) values(?, ?)", args);Named argumentsMap<String, Object> args = new HashMap<>();
args.put("id", 2);
args.put("name", "Alice");
int res = jdbc.executeUpdate("insert into users (id, name) values(:id, :name)", args);
Return Value
JdbcTemplate executes SQL through PreparedStatement or Statement. The SQL must be DML or a statement with no result set.
- DML (INSERT/UPDATE/DELETE): return value = affected rows.
- Statements with no return content (e.g., DDL): return value =
0.
info
Although JDBC specifies the behavior above, actual drivers may behave differently. Refer to your JDBC driver documentation for exact semantics.