Why does JDBC driver pad some blank characterS other a queried field, from an Oracle Database?

Don't forget to trim your values while using char . Or don't use char use varchar2 until you are providing the exact sized value as the column size.

Up vote 3 down vote favorite 1 share g+ share fb share tw.

So, here is the code which create the table in an Oracle 10g / UTF-8 database : CREATE TABLE TEST_SEMANTIC ( SEMANTIC_COLBYTE char(2 byte) , SEMANTIC_COLCHAR char(2 char) ); meaning, that I use two differents types of semantic for the two columns, byte and char. I then insert inside the database these corresponding data : insert into test_semantic(SEMANTIC_COLBYTE,SEMANTIC_COLCHAR) values('é','é'); So when I use the JDBC driver to query the database in a java program, and display the result, I expect an output like this : Byte>éééé "+output_byte+""+output_char+".

Don't forget to trim your values while using char. Or don't use char, use varchar2, until you are providing the exact sized value as the column size. You might want to know why, so here it is.

Thanks for your answer and the link. Actually, I know the difference between char and varchar2. And the corresponding string I store in database, is not variable, but predefined on 2 character, but in UTF-8 semantic (under Oracle).

More precisely, my question is : By knowing the UTF-8 rule to convert non ascii char(fr.wikipedia.org/wiki/UTF-8), why does my java program don't give me a least : >é é Sorry for misunderstanding. The value is from the driver actually. So, this the way driver implemented it.

Can't be done much, trimming the value is your best bet. – Adeel Ansari Dec 16 '09 at 11:19 BTW, is your SQL client is also Java based? – Adeel Ansari Dec 16 '09 at 11:20 Yep, as far as I know, SqlDevelopper is java based, but I don't know which driver it uses.

– zor Dec 16 '09 at 14:55 What jar are you using? Try ojdbc5 or ojdbc6. Or if nothing work then you might want to try OCI drivers.

I suppose SQL Developer uses the same, as they are having platform specific downloads for SQL Developer, and OCI suits stand-alone apps. – Adeel Ansari Dec 16 '09 at 16:16.

CHAR Datatype: The CHAR datatype specifies a fixed-length character string. Oracle ensures that all values stored in a CHAR column have the length specified by size. If you insert a value that is shorter than the column length, then Oracle blank-pads the value to column length.

Yes, of course, It seems to me that my question imply the understanding of Oracle length semantics. – zor Dec 16 '09 at 14:59 1 Just checkin', and others who find this question in search of an answer to a problem they've got have might not have read it. – David Aldridge Dec 16 '09 at 15:47.

Which characterset is the database (and your session) actually in. Mine was in AL32UTF8 and wouldn't accept 'é' in a 2 byte CHAR field. In a 4 byte field, it went to Typ=96 Len=4: ef,bf,bd,20 A UTF-8 character can be four bytes and therefore the CHAR(2 char) can be up to eight bytes.

So I could understand a string of length 8 coming out. Seven is a bit odd, almost like it was told the first character is three bytes and the second character can be up to four. Can you play with ResultSetMetaData (eg getColumnDisplaySize, getColumnTypeName) and see what comes out.

Not seven bytes - seven characters. The é will be two bytes. The remaining 6 bytes are padding - space characters taking one byte each.

Given that the dump function shows only 3 bytes, though, this does look like a problem with the JDBC driver as Vinegar has suggested. – Alohci Dec 18 '09 at 11:34 Don't know how you got to ef bf bd. That's U+FFFD, the replacement character for characters that are unknown or unrepresentable.

– Alohci Dec 18 '09 at 12:01 My database is in UTF-8 charset – zor Jan 5 '10 at 12:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions