Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / July 2004

Tip: Looking for answers? Try searching our database.

problem with iso-8859-2 chars, oracle rdb, jdbc

Thread view: 
Krzysztof Sobczuk - 28 Jul 2004 17:48 GMT
Hello,

I am dealing with a problem connected with special polish iso-8859-2
characters between Oracle Rdb, Oracle SQL/Services on server side and jdbc
on client side.

Oracle Rdb OCI Server Release 7.1.5.9.1 - Production, Level 1.7;
Oracle Rdb SQL Release 7.0.7.3.0 - Production;
CORE Version 4.0.5.0.0 - Production;
TNS for VMS: Version 8.0.5.0.2 - Production;
NLSRTL Version 3.3.2.0.0 - Production;
Metadata Views Version 7.1.5.9.0 - Production;
Oracle Compatible Release 8.0.5.1.0;

Database is in WE8DEC charset and NLS_LANG on server side is set to WE8DEC.
Specific polish characters in database have ISO-8859-2 codes:
a1 c6 ca a3 d1 d3 a6 ac af (9 big chars)
b1 e6 ea b3 f1 f3 b6 bc bf (9 small chars)

1. When I use jdbc oci driver polish iso-8859-2 characters are transferred
to client as:
a1 c6 ca a3 d1 d3 a6 ac af b1 e6 ea b3 f1 f3 b6 bc bf
So it is ok so far.

After conversion in jdbc driver I get something like this:

C2 A1 C3 86 C3 8A C2 A3 C3 91 C3 93 EF BF BD EF
BF BD EF BF BD C2 B1 C3 A6 C3 AA C2 B3 C3 B1 C3
B3 C2 B6 C2 BC C2 BF

or depending on method of retrieving from resultset
A1 C6 CA A3 D1 D3 FD FD FD B1 E6 EA B3 F1 F3 B6
BC BF

Three last big polish chars have incorrect codes "FD".

2. When I use jdbc thin driver polish iso-8859-2 characters are transferred
to client as:
C2 A1 C3 86 C3 8A C2 A3 C3 91 C3 93 EF BF BD EF
BF BD EF BF BD 20 C2 B1 C3 A6 C3 AA C2 B3 C3 B1
C3 B3 C2 B6 C2 BC C2 BF

Here three last big polish chars have incorrect codes "EF BF BD" even before
they reach jdbc driver.

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?
What do I have to do to get proper iso-8859-2 chars from jdbc driver?

Thanks for any suggestions,
Krzysiek Sobczuk
Lothar Kimmeringer - 28 Jul 2004 18:07 GMT
[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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.