Strange behaviour of JDBC query for CHAR column
523283Jul 14 2006 — edited Sep 7 2006Hi,
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.