Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4071046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:42:24+00:00 2026-05-20T16:42:24+00:00

I have a tricky issue with the Oracle JDBC driver’s handling of CHAR data

  • 0

I have a tricky issue with the Oracle JDBC driver’s handling of CHAR data types. Let’s take this simple table:

create table x (c char(4));
insert into x (c) values ('a');  -- inserts 'a   '

So when I insert something into CHAR(4), the string is always filled with whitespace. This is also done when I execute queries like this:

select * from x where c = 'a';    -- selects 1 record
select * from x where c = 'a ';   -- selects 1 record
select * from x where c = 'a   '; -- selects 1 record

Here, the constant 'a' is filled with whitespace as well. That’s why the record is always returned. This holds true when these queries are executed using a JDBC PreparedStatement as well. Now the tricky thing is when I want to use a bind variable:

PreparedStatement stmt = 
  conn.prepareStatement("select * from x where c = ?");
stmt.setString(1, "a");    // This won't return any records
stmt.setString(1, "a   "); // This will return a record
stmt.executeQuery();

This is a workaround:

PreparedStatement stmt = 
  conn.prepareStatement("select * from x where trim(c) = trim(?)");
stmt.setString(1, "a");    // This will return a record
stmt.setString(1, "a   "); // This will return a record
stmt.executeQuery();

EDIT: Now these are the constraints:

  • The above workaround is not desireable as it modifies both the contents of c and ?, AND it makes using indexes on c quite hard.
  • Moving the column from CHAR to VARCHAR (which it should be, of course) is not possible

EDIT: The reasons for these constraints is because I ask this question from the point of view of the developer of jOOQ, a database abstraction library. So my requirements are to provide a very generic solution that doesn’t break anything in jOOQ’s client code. That is why I’m not really a big fan of the workaround. And that’s why I don’t have access to that CHAR column’s declaration. But still, I want to be able to handle this case.

What would you do instead? What’s a good practice for handling CHAR data types when I want to ignore trailing whitespace?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:42:25+00:00Added an answer on May 20, 2026 at 4:42 pm

    If you want

    stmt.setString(1, "a");    // This won't return any records
    

    to return a record, try

    conn.prepareStatement("select * from x where c = cast(? as char(4))")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple issue, but the solution appears to be tricky. I want
I have a tricky issue with gmake, when I build from the parent directory,
I have one very tricky issue that I am not able to sort out
This is a bit of a tricky one. I have Document entities that are
this is kind of tricky: I have an C# web application running always on
I have a tricky issue redirecting some URLs internally for my site. The situation
This is a tricky one to explain. So I'll bullet point it: I have
We have an issue whereby not-nullable fields in our Oracle database do not exist
I am trying to build a website and have encountered a tricky issue with
I have a tricky problem that has had me scratching my head for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.