My Oracle Support Banner

In UCP PreparedStatement equals() Method Is Not Working (Doc ID 1158216.1)

Last updated on FEBRUARY 03, 2019

Applies to:

JDBC - Version 11.1.0.7 to 11.1.0.7 [Release 11.1]
Universal Connection Pool - Version 11.1.0.7.0 and later
Information in this document applies to any platform.

Symptoms

Currently, if a PreparedStatement or Statement is created from a connection that was obtained from a UCP DataSource, if you insert it as a key to a ConcurrentHashMap you will not be able to retrieve it via the same key, which is itself. If you additionally just try to do something like:

PreparedStatement pstmt = conn.prepareStatement("some sq");
pstmt.equals(pstmt)

will result in false which is not correct.

This would seem that the equals method has not been properly accounted for perhaps when used by a Proxy, which is what UCP uses.
If the connection was established via the DriverManager for example, if you do the same equals condition, it returns true, which is correct and that ultimately is using the same wrapper class.

Here is a sample code for this test:


package ucp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

public class Equals
{

public static void main(String[] args)
throws SQLException
{
PoolDataSource pds = null;
// Create pool-enabled data source instance.
pds = PoolDataSourceFactory.getPoolDataSource();
// PoolDataSource and UCP configuration

//set the connection properties on the data source and pool properties

pds.setUser("scott");

pds.setPassword("tiger");
pds.setURL("jdbc:oracle:thin:@//mhernand-pc2.us.oracle.com:1522/db11g");

pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setInitialPoolSize(10);
pds.setMinPoolSize(10);
pds.setMaxPoolSize(20);


Connection conn = pds.getConnection();
PreparedStatement pstmt = conn.prepareStatement("select ename from emp");

// This should be true and isn't!
System.out.println("Equals = " + pstmt.equals(pstmt));

// How can I get an exception on asking if a statement is closed????
try
{
System.out.println("Statement closed = " + pstmt.isClosed());
pstmt.close();
System.out.println("Statement closed = " + pstmt.isClosed());
}
catch (Exception e)
{
e.printStackTrace();
}

}
}




Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Cause
Solution
References


This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.
My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.