简体   繁体   中英

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.

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 (ie 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.

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.

Of course you can hold multiple open cursors while you're issuing other queries on the same connection. However, it's not possible to issue other queries or statements while the first cursor is beeing opened. That's because only one request can be active (ie beeing executed) in an Oracle session at any point in time.

You can use the concept of database pooling.

Click Here

It provides a pool of database connections so whenever needed you can get a database connection from pool.

It is also memory optimized since database connection and closing is a heavy process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM