Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How do I get unicode characters out of an oracle.xdb.XMLType in Java?

698912May 27 2009 — edited May 28 2009
The subject says it all. Something that should be simple and error free. Here's the code...

String xml = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<x>\u2026</x>\n");
XMLType xmlType = new XMLType(conn, xml);

conn is an oci8 connection.

How do I get the original string back out of xmlType? I've tried xmlType.getClobVal() and xmlType.getString() but these change my \u2026 to 191 (question mark). I've tried xmlType.getBlobVal(CharacterSet.UNICODE_2_CHARSET).getBytes() (and substituted CharacterSet.UNICODE_2_CHARSET with a number of different CharacterSet values), but while the unicode characters are encoded correctly the blob returned has two bytes cut off the end for every unicode character contained in the original string.

I just need one method that actually works.

I'm using Oracle release 11.1.0.7.0. I'd mention NLS_LANG and file.encoding, but I'm setting the PrintStream I'm using for output explicitly to UTF-8 so these shouldn't, I think, have any bearing on the question.

Thanks for your time.

Stryder, aka Ralph

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 25 2009
Added on May 27 2009
2 comments
2,174 views