How can I achieve that result using execute() method.
You can't. It will only return true
if the result has a ResultSet
. If there is a problem with your insertion, the method will throw an exception. From the documentation:
boolean execute(String sql) throws SQLException
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException - if a database access error occurs, this method is called on a closed Statement, the method is called on a PreparedStatement or CallableStatement
SQLTimeoutException - when the driver has determined that the timeout value that was specified by the setQueryTimeout method has been exceeded and has at least attempted to cancel the currently running Statement