Does Oracle DB support multiple (parallel) operati

2019-02-17 17:39发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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 (i.e. beeing executed) in an Oracle session at any point in time.



回答4:

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.