Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Phani Kumar.

Asked: December 13, 2016 - 3:14 pm UTC

Last updated: January 12, 2017 - 1:54 am UTC

Version: Oracle 12c

Viewed 1000+ times

You Asked

Hi Tom,

I'm a java developer, actually we are planning to implement DRCP for upcoming project.

Regarding Database Resident Connection Pooling (DRCP)
Actually UCP documentation provided the information like "how we can connect to Connection Broker system?". But, It didn't have any information regarding Connection broker system configuration and how Connection broker system connects to other systems.
So, here my questions as follows,
How to setup connection pool on database? Either DBA will create this or we do?
How to setup connection broker?.. i really want to know how it will be.
How does can broker talk to oracle server?
How does application connect to Broker? will these details provided by DBA or by someone.

Could you please give me some clear information if you have on this and if possible please provide some links how to implement this from java end.

Thanks Tom,
Phani..

and Connor said...

There's a nice whitepaper here on it

http://www.oracle.com/technetwork/articles/oracledrcp11g-1-133381.pdf

but in terms of setting it up and connecting, its pretty straightforward, eg

as sysdba

SQL> exec dbms_connection_pool.start_pool;

PL/SQL procedure successfully completed.


and then when I connect, I nominate a pooled connection type

--
-- normal
--
SQL> conn scott/tiger@//localhost:1521/db11
Connected.
SQL> select server from v$session where username = 'SCOTT';

SERVER
---------
DEDICATED

--
-- pooled
--
SQL> conn scott/tiger@//localhost:1521/db11:POOLED
Connected.
SQL> select server from v$session where username = 'SCOTT';

SERVER
---------
POOLED


It appears from the docs, that you would do with this with a tnsnames entry, or explicitly in the connection as I did because I saw this:

"WebLogic Server does not support defining the oracle.jdbc.DRCPConnectionClass as a system property. It must be defined as a connection property in the data source descriptor"


See https://docs.oracle.com/middleware/1212/wls/JDBCA/ds_oracledriver.htm#JDBCA653 for more details.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Phani Kumar, January 10, 2017 - 3:59 pm UTC

Hello AskTom,

Thanks for the information which you given before on DRCP Connection Broker Info. It helped me a lot.

A Quick Question.....

(Java)Program:-

package com.pvc.spring.ucp.drcp;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;

public class UcpWithDRCP {

/*
* The sample shows how to use DRCP with UCP. Make sure that correct
* connection URL is used and DRCP is enabled both on the server side and on
* the client side.
*/
static public void main(String args[]) throws SQLException {

PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setUser("sys as sysdba");
pds.setPassword("admin");

// Make sure that DRCP_URL has (SERVER=POOLED) specified
pds.setURL("jdbc:oracle:thin:@//localhost:1521/orcl:POOLED");
pds.setConnectionPoolName("DRCP_UCP_Pool");
// Set UCP Properties
pds.setInitialPoolSize(2);
pds.setMinPoolSize(4);
pds.setMaxPoolSize(10);

// DRCP
Properties prop = new Properties();
prop.put("oracle.jdbc.DRCPConnectionClass", "DRCP_UCP_Pool");
pds.setConnectionProperties(prop);

Connection conn = pds.getConnection();

// Get the Database Connection from Universal Connection Pool.
try (Connection conn1 = pds.getConnection()) {
System.out.println("\nConnection obtained from UniversalConnectionPool");
// Perform a database operation
doSQLWork(conn1);
System.out.println("Connection returned to the UniversalConnectionPool");

}
}

public static void doSQLWork(Connection connection) throws SQLException {
// Statement and ResultSet are auto-closable by this syntax
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("select SYSDATE from DUAL")) {
while (resultSet.next())
System.out.print("Today's date is " + resultSet.getString(1) + " ");
}

}

System.out.println("\n");
}
}

------------------------------------------------------------
when we run this program, we are getting following db info as follows...

SYS.DRCP_UCP_Pool-> 2(NUM_REQ) 0(NUM_HITS) 2(NUM_MISSES) 0(NUM_WAITS) 0(WAIT_TIME) 0(CLIENT_REQ_TIMEOUTS) 1(NUM_AUTHENTICATIONS) 0(CON_ID).

when we observe this data, we identified the issue like NUM_HITS = 0 and NUM_MISSES> 0.


That looks strange, we have just created 2 connections and none of them had been reused.

I am not understanding , why it is behaving like this.
Could you please help me on this and last thing i just want to know that the following..
Is we can create a different connection brokers for different microservices..?

Thank you,
Phani Kumar.
Connor McDonald
January 12, 2017 - 1:54 am UTC

Sorry - once you get down into Java land, I'm not much use :-)

I'd post this on the JDBC forum

https://community.oracle.com/community/java/database_connectivity/java_database_connectivity


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library