Java query with DB Link does not close the Db Link connection

933 Views Asked by At

I have a Java code that connects to Database A. Database A has DB link to Database B. Both database are oracle.

I make a JPA connection to Database A Then I run a query from joining a table from DAtabase A to table in Database B Then Close connection to Database A Simple code.

I am still seeing the DB link connections on Database B is open. It is not closing. Any idea why? I am assuming that it should be internally handled right?

Thoughts?

1

There are 1 best solutions below

3
Marmite Bomber On

If you close a connection to the database all database link connections are automatically closed.

So if you observes open link sessions, they stem from other not yet closed connections.

The database link connection is from performance reasons not closed immediately after each distributed query, but is intentionally left open to be reused in the potential next statement.

Anyway you can excplicitely close the link connection using a call of either

 alter session close database link  link_name

or

DBMS_SESSION.CLOSE_DATABASE_LINK('link_name')

es illustrated here. This is mainly done in case you hit the limit of maximal open links