Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Oracle DB support multiple (parallel) operations per connection?

My Java application needs to hold cursor to Oracle DB for some time. During it other DB statements have to be made. Does this require separate DB connections or same (cursor's one) can be used?

Thanks.

like image 689
Ralkie Avatar asked May 10 '11 08:05

Ralkie


2 Answers

The only restriction is that a single statement can only have a single ResultSet at a given time. Note that a statement can produce multiple ResultSets but you have to access them sequentially (using getNextResult())

To be able to have multiple open ResultSets/Cursors you need multiple java.sql.Statement objects.

A single connection can only have a single active (i.e. running) statement. So if you have need multiple open cursors (ResultSets) you need to run them sequentially (one after the other) each with their own Statement object.

like image 176
a_horse_with_no_name Avatar answered Oct 17 '22 01:10

a_horse_with_no_name


Oracle has no problem with what the MSSQL folks call MARS (Multiple active result sets).

You can see this kind of thing in a lot of PL/SQL code, and for that matter PL/SQL is "just" a client to the SQL engine as is your Java code:

for a in (select field1, field2 from table1) loop
  for b in (select * from table2 where SomeField = a.Field1) loop
    ...
  end loop;
end loop;

Don't take my word for it, though. You can create a nested loop like this yourself in Java.

like image 4
Robert Giesecke Avatar answered Oct 17 '22 00:10

Robert Giesecke