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 to [Release 11.1]
Universal Connection Pool - Version and later
Information in this document applies to any platform.


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");

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




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????
System.out.println("Statement closed = " + pstmt.isClosed());
System.out.println("Statement closed = " + pstmt.isClosed());
catch (Exception e)



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

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.