Oracle JDBC Returning Junk for CHAR

Slaimus

Senior member
Sep 24, 2000
985
0
76
Using Oracle 10g and ojdbc14.jar thin driver, but it has occured in Oralce 9, as well as using classes12.jar driver.
The data in the DB is CHAR(1) and is storing "Y" or "N"

The result is registered as oracle.jdbc.OracleTypes.CHAR, but I have also tried VARCHAR and java.sql.Types.CHAR and VARCHAR

For some reason, when I do statement.getString(#) for that item, it return a String with length 32512 instead of 1. I can do charAt(0) or trim() to get the right value.

It works perfectly fine if the data is defined as VARCHAR2(1) in the database instead of CHAR(1).

When am in SQLPlus, it returns it properly, so it must be JDBC related. It looks almost like a lack of null termination for the string.

Has anyone came across this before or have a solution?
 

Slaimus

Senior member
Sep 24, 2000
985
0
76
I thought the NLS classes are only needed if you use non-western character sets.
 

Slaimus

Senior member
Sep 24, 2000
985
0
76
Yeah it is still doing this. Could it be that I am using a CallableStatement instead of PreparedStatement?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
That should depend on if you're trying to execute a query or a stored proc. I haven't found jdbc drivers to be very consistent in their handling of CallableStatement, although I've never used Oracle. IIRC, postgres gave me similar troubles when using CallableStatement to call procs and I got around it by using PreparedStatement.
 

Slaimus

Senior member
Sep 24, 2000
985
0
76
I am calling a PL/SQL procedure. The implementation of CallableStatement I am using is com.evermind.sql.OrclCallableStatement, which is in Oracle OC4J version 9.0.4.0.0

EDIT: I just tried OC4J 10.1.2.0.0 and the same thing still happens.