views:

69

answers:

1

Or simpler, I have this code (Oracle database)

SELECT TO_NUMBER (tkb.id_kucnog_broja) id, 'Buildings and home numbers' vrsta_pj,

and in Java I have this

for (int j = 0; j < rs.getMetaData().getColumnCount(); j++) {
data = rs.getString(j + 1);
}

and the result it gets is 'Buildings and home number', meaning it 'cuts' the last char (same thing if I change the string). I can make the string with 2 's' chars, but I'd really like to know why does this happen.

EDIT:

Managed to pinpoint the problem. The real string is 'Zgrade i kućni brojevi' (I've translated it here) and it seems the sign 'ć' (and i'm guessing any other like 'š' or 'đ') is(are) the problem. If I write any sized string (didn't experiment too much, got a lot of work :) ) and don't put in croatian 'special' signs, everything is ok, but the moment I put it in, the string gets shortened by one char. What's specially interesting is that it works just fine when I execute it in Toad.

EDIT2: Seems croatian special chars take 2 places. If I put '\u107' the problem remains. I can make a workaround (write '&#263;' or add any string at the end of this one) so the problem is solved (in a way that I know how to get the job done) but I'm still curious how to do it properly.

+1  A: 

Basically, a database is not just a data dump. When you insert/update/select a string (VARCHAR2/NVARCHAR2/CHAR/NCHAR/CLOB) from a database it takes into consideration the characterset of the client and the database and performs any necessary conversion.

Some characterset are single bye, some are fixed length multi-byte (eg all characters take two bytes) and some are variable length multi-byte (eg common characters take one byte, 'special' characters take between two and four).

So you need to consider the length of the string in the database (in bytes and characters) and the length of the string in Java (again in bytes/characters). I suspect you are ending up with the length of the java string in characters, but then treating that as the length in bytes.

Worth checking your drivers.

Gary