Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DataSource getConnection returns null

843859Feb 7 2006 — edited Nov 20 2014
Hello,

I hope that someone is able to help.

I have an application that is using jdbc (Oracle) to connect to a database. I'm creating an OracleDataSource, and trying to work out why "null" is returned from the Oracle JDBC drivers when I try and get a Connction from the database. I am using the "thin" drivers as these seem to work better than the "oci" ones.

I am fairly convinced that it is to do with the OracleDataSource running out of pooled connections.

Howerver the javadocs for javax.sql.DataSource and oracle.jdbc.pool.OracleDataSource do not indicate that "null" is a valid return value or why it would be returned. I am not getting a SQLException which I would expect if an error had occured (such as the pool running out).

I have been trawling the net trying to find reference to getConnection and I have pretty much drawn a blank, the only reference I have found is to use oracle.jdbc.pool.OracleConnectionCacheImpl and set a Cache Scheme as described here http://www.lc.leidenuniv.nl/awcourse/oracle/java.920/a96654/connpoca.htm#1065568 I think the behaviour I want is as described for DYNAMIC. But this method is deprecated and just says to use JDBC Implicit Connection Caching instead, which is what I think I am currently doing.

The code snippet below is how I am creating and setting up the OracleDataSource.

m_ODS = new OracleDataSource();
try
{
m_ODS.setDriverType("thin");
m_ODS.setPortNumber(1521);

m_ODS.setServerName(IP_ADDRESS);
m_ODS.setDatabaseName(DB_NAME);
m_ODS.setUser(USER);
m_ODS.setPassword(PASWORD);

m_ODS.setConnectionCachingEnabled(true);

m_ODS.setImplicitCachingEnabled(true);
m_ODS.setExplicitCachingEnabled(true);

final Properties prop = new Properties();

prop.setProperty("MinLimit", Integer.toString(MIN_CONNECTIONS));
prop.setProperty("MaxLimit", Integer.toString(MAX_CONNECTIONS));
prop.setProperty("InitialLimit", Integer.toString(MIN_CONNECTIONS));

prop.setProperty("MaxStatementsLimit", Integer.toString(25));

prop.setProperty("PropertyCheckInterval", "60");

prop.setProperty("ConnectionWaitTimeout", "10");

prop.setProperty("InactivityTimeout", "120");

prop.setProperty("AbandonedConnectionTimeout", "360");

m_ODS.setConnectionCacheProperties(prop);
}

I don't think that I am overly using the connection pool. I have 100 threads each trying to insert data twice a second (500 ms apart) on a pool size of 30 connections. I get a "null" connection after about 12 or so seconds. It is then intermittent after this.

Any help you can give would be really appreciated, even if it is a recommended way of dealing with the "null" return if it is expected behaviour.

Best regards,

Dan.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2009
Added on Feb 7 2006
3 comments
3,220 views