Execution time of sequential executeUpdate () SQL statements

How safe is it to use multiple consecutive executeUpdate () methods in an SQL database?

Given two statements:

st.executeUpdate("INSERT table SELECT col1,col2 FROM table WHERE ID=" +var_id); st.executeUpdate("DELETE FROM table WHERE ID=" +var_id); 

How do they behave? Does the 2nd operator mean the completion of the 1st or should we check the return value (the number of rows affected) and act accordingly with the 2nd operator?

+6
source share
3 answers

The call to executeUpdate not asynchronous, so it will not be returned until the statement is executed on the server. In other words: these two statements will work, and they will not intervene, because they are executed one after the other.

+4
source

I do not think that this operator can execute several requests at the same time as one instance.

The second statement will wait until the first is completed and returns.
The second statement will be installed only with a new request after the first completion.

This also applies when reading a ResultSet.
The documentation reads:

By default, only one ResultSet for a Statement can be opened at a time. Therefore, if reading one ResultSet object alternates with reading another, each of them should be generated by different Statement objects. All execution methods in the Statement interface implicitly close the current ResultSet if one exists.

+1
source

The answer depends on whether your gas station is enabled for your database.

If you have autorun enabled, the second statement will wait for the completion and completion of the first statement before execution.

If autoload is disabled, the second statement will be executed after the first statement, but no changes will be applied to the database until commit.

+1
source

Source: https://habr.com/ru/post/920136/


All Articles