JdbcTemplate.update()
returns number of rows affected - so you not only know that delete/update was sucessfull, you also know how many rows were deleted/updated.
What will be the return value if I try to insert a row.
Is it possible to get return value as "0"??
private static final String insertSql =
"INSERT INTO employee (" +
" name, " +
" surname, " +
" title, " +
" created) " +
"VALUES (John, Smith, Software developer, new Date())";
int row = template.update(insertSql, params, types);
Yes, in theory you should get 0 or 1, but if no row was inserted, it would be due to an error, so a DataAccessException
would be thrown, which is how you would know that something went wrong and no row was created.
jdbctemplate.update will return in integer format as we know. in order to find 0 or 1 just do this below simple code
int i=jdbctemplate.update(.your db call..);
it will return 1 for success and 0 for failure case so, according to it you can process your logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With