Skip to Main Content

Java and JavaScript in the Database

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!

Strange behaviour of JDBC query for CHAR column

523283Jul 14 2006 — edited Sep 7 2006
Hi,

I have a simple table with char type and several records in the table.
create table char_test(str char(50));
insert into char_test values ('abc');
insert into char_test values ('abc ');
insert into char_test values ('abc ');

In JDBC, if I have a query like
PreparedStatement st = conn.prepareStatement("select str from char_test where str = 'abc'");
ResultSet rs = st.executeQuery();
All three rows will be returned.

However, If I use parameter for the PreparedStatment, nothing will be returned if the value of the parameter is passed as "abc".
PreparedStatement st = conn.prepareStatement("select str from char_test where str = ?");
st.setString(1, "abc");
ResultSet rs = st.executeQuery();

Personally, I think this is a bug of Oracle JDBC driver. Could anybody please give me any explanation?

Thanks,
Bill

PS. I'm using Oracle 10g Release 2 DB and ojdbc14.jar under jdk 1.5.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 5 2006
Added on Jul 14 2006
4 comments
2,853 views