PreparedStatement and Hibernate(JPA) Not Returning Results When Database Column Is CHAR (Doc ID 1327363.1)

Last updated on SEPTEMBER 01, 2014

Applies to:

JDBC - Version 11.2.0.2.0 and later
Information in this document applies to any platform.

Symptoms


The following code does not return any results if the type of column in the database is CHAR, e.g. CHAR(6):

PreparedStatement statement = connection.prepareStatement("select * from customer where Last_Name= ?");
statement.setString(1, "XXXX");
resultSet = statement.executeQuery();


If the values are hard coded, then the rows are returned where the values match:

PreparedStatement statement = connection.prepareStatement("select * from customer where Last_Name = 'XXXX'");
resultSet = statement.executeQuery();


Cause

Sign In with your My Oracle Support account

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

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms