[Problems with 8859_2 and Oracle JDBC]
> I suppose the problem is in jdbc driver classes and native sql procedures on
> server side which convert oracle
> chars to unicode and vice versa. There not exists proper mapping of
> charaters?
Maybe the characters are already wrong when being added as
parameter to your statement. Maybe some code being posted
might be helpful.
> What do I have to do to get proper iso-8859-2 chars from jdbc driver?
You can try to set the characters as stream instead of using
the setString()-method, using an OutputStreamWriter with explicitly
set 8859_2 to be used for encoding.
Regards, Lothar

Signature
Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
Krzysztof Sobczuk - 29 Jul 2004 10:34 GMT
> [Problems with 8859_2 and Oracle JDBC]
> > I suppose the problem is in jdbc driver classes and native sql procedures on
[quoted text clipped - 5 lines]
> parameter to your statement. Maybe some code being posted
> might be helpful.
The problem appears even when I retrieve data from database.
PreparedStatement stmt = con.prepareStatement("select str from table ....");
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
//1 byte[] bytes = rs.getBytes(1);
//2 String str = rs.getString(1);
//3 InputStream input = rs.getAsciiStream(1);
// ByteArrayOutputStream output = new ByteArrayOutputStream();
// CopyUtils.copy(input, output);
// byte[] bytes = output.toByteArray();
}
The str column is VARCHAR. However I retrieve data (1,2,3) I always get
wrong bytes. It is because the jdbc driver first of all determines the types
of result. The str is VARCHAR so the driver will convert sent data to
unicode. I am sure that characters in db have correct iso-8859-2 codes. Look
at the piece of code:
PreparedStatement stmt = con.prepareStatement("select str from table ....");
OraclePreparedStatement ostmt = (OraclePreparedStatement) stmt;
ostmt.defineColumnType(1, OracleTypes.RAW);
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
byte[] bytes = rs.getBytes(1);
String str = new String(bytes, "ISO-8859-2");
}
When I enforce RAW type everything is ok. Created string str has proper
iso-8859-2 characters.
> > What do I have to do to get proper iso-8859-2 chars from jdbc driver?
>
> You can try to set the characters as stream instead of using
> the setString()-method, using an OutputStreamWriter with explicitly
> set 8859_2 to be used for encoding.
Like I said, the Jdbc driver determines the types before fetching the data
and when it finds out the VARCHAR it do the automatic conversion.
Casting statements to OracleStatements and defining column types is not the
best solution. Retrieving strings should be done transparently and driver
should do any needed character conversion.
Regards,
Krzysiek