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

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

I created analogic test case, and executed it with DB 11.1.0.7 (Linux x86), which seems to work fine.
Please refer to the execution procedure below:
* I used AL32UTF8 database.
1. Create simple test case by executing the following SQL script from SQL*Plus:
connect / as sysdba
create user testxml identified by testxml;
grant connect, resource to testxml;
connect testxml/testxml
create table testtab (xml xmltype) ;
insert into testtab values (xmltype('<?xml version="1.0" encoding="UTF-8"?>'||chr(10)||'<x>'||unistr('\2026')||'</x>'||chr(10)));
-- chr(10) is a linefeed code.
commit;
2. Create QueryXMLType.java as follows:
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.*;
import oracle.xdb.XMLType;
import java.util.*;
public class QueryXMLType
     public static void main(String[] args) throws Exception, SQLException
          DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
          OracleConnection conn = (OracleConnection) DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:orcl", "testxml", "testxml");
          OraclePreparedStatement stmt = (OraclePreparedStatement)conn.prepareStatement("select xml from testtab");
          ResultSet rs = stmt.executeQuery();
          OracleResultSet orset = (OracleResultSet) rs;
          while (rs.next())
               XMLType xml = XMLType.createXML(orset.getOPAQUE(1));
               System.out.println(xml.getStringVal());
          rs.close();
          stmt.close();
3. Compile QueryXMLType.java and execute QueryXMLType.class as follows:
export PATH=$ORACLE_HOME/jdk/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export CLASSPATH=.:$ORACLE_HOME/jdbc/lib/ojdbc5.jar:$ORACLE_HOME/jlib/orai18n.jar:$ORACLE_HOME/rdbms/jlib/xdb.jar:$ORACLE_HOME/lib/xmlparserv2.jar
javac QueryXMLType.java
java QueryXMLType
-> Then you will see U+2026 character (horizontal ellipsis) is properly output.
My Java code came from "Oracle XML DB Developer's Guide 11g Release 1 (11.1) Part Number B28369-04" with some modification of:
- Example 14-1 XMLType Java: Using JDBC to Query an XMLType Table
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28369/xdb11jav.htm#i1033914
and
- Example 18-23 Using XQuery with JDBC
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28369/xdb_xquery.htm#CBAEEJDE

Similar Messages

  • Trying to get UTF-8 data in and out of an oracle.xdb.XMLType

    I need to be able to put unicode text into an oracle.xdb.XMLType and
    then get it back out. I'm so close but it's still not quite working.
    Here's what I'm doing...
    // create a string with one unicode character (horizontalelipsis)
    String xmlString = new String(
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
    "<utf8>\n" +
    " <he val=\"8230\">\u2026</he>\n" +
    "</utf8>\n");
    // this is an oci8 connection
    Connection conn = getconnection();
    // this works with no exceptions
    XMLType xmlType = XMLType.createXML(conn, xmlString);
    // this is the problem here - BLOB b does not contain all the bytes
    // from xmlType. It seems to be short 2 bytes.
    BLOB b = xmlType.getBlobVal(871);
    String xmlTypeString = new String(b.getBytes(1L, (int) b.length()), "UTF-8");
    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    out.print(xmlTypeString);
    out.close();
    What I get from this is this...
    <?xml version="1.0" encoding="UTF-8"?>
    <utf8>
    <he val="8230">[utf-8 bytes]</he>
    </utf8
    In the above, [utf-8 bytes] represents the correctly encoded UTF-8 bytes that
    were returned. But the output is missing the final closing bracket and the
    newline at the end. It seems that no matter what second argument I give b.getBytes(),
    it always returns the above. Even
    It seems that this code...
    BLOB b = xmlType.getBlobVal(871);
    always returns a BLOB that contains a few bytes short of what it should contain.
    What am I doint wrong? I'm sure I'm missing something here.
    Thanks much for your help.
    Here's info about the environment I'm working in.
    ============================ SYSTEM INFORMATION ============================
    SQL*Plus: Release 11.1.0.7.0 - Production on Fri May 15 11:54:34 2009
    select * from nls_database_parameters
    where parameter='NLS_CHARACTERSET'
    returns...
    WE8ISO8859P1
    select * from nls_database_parameters
    where parameter='NLS_NCHAR_CHARACTERSET'
    returns...
    AL16UTF16
    The operating system I'm working with is...
    SunOS hostname 5.10 Generic_120011-14 sun4u sparc SUNW,Netra-T12

    WE8ISO8859P1 does not support the ellipsis character. It is a WE8MSWIN1252 character. I wonder if your problem may have something to do with internal conversion to/from XML character reference (&#x2026). Unfortunately, I have no time to test. Please, try to use a simple loop and System.out.print to print all bytes of the return value of b.getBytes(1L, (int) b.length()). Also, check the value of b.length().
    -- Sergiusz

  • I have and iPad and I have and iPhone 5 my husband has another one and I singed all of them with the same Apple ID and  accound now my husband can see all the text I send and I get everything he gets how could I get his phone out of my accound

    I have and iPad and I have and iPhone 5 my husband has another one and I singed all of them with the same Apple ID and  accound now my husband can see all the text I send and I get everything he gets how could I get his phone out of my accound

    Mishijos3 wrote:
    I have and iPad and I have and iPhone 5 my husband has another one and I singed all of them with the same Apple ID ...
    Have a look here...
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • How can I get the best out of my battery life?

    There are a variety of things you can do to extend your device battery life, and use your phone for longer periods of time to see you through the day.
    Set your screen to timeout after a period of inactivity. This way your phone is not sitting idle with the screen backlight consuming extra energy. The recommended screen timeout is 30 seconds, but most phones will allow from 15 seconds to 10 minutes.
    Turn off location services (GPS), Wi-Fi and Bluetooth when not using these functions. When they're on, your phone constantly searches for your current location and open networks, which has a big impact on battery life.
    Turn down the screen brightness. For example, on an iPhone 4 the lowest brightness setting gives roughly 6.5 hours of continuous use, whereas the highest setting gives roughly 3.5 hours. You can always adjust the brightness when you're outside so you can still see your screen clearly. Some devices have an auto-brightness setting, where the phone adjusts the screen brightness depending on the light around it.
    Close your applications. On smartphones, returning to the ‘home' screen only minimises your apps – they keep running in the background. Closing your apps fully will save power; for example, on Samsung Galaxy devices hold down the home button for two seconds to see a list of all open apps. You can then swipe these to the left of the screen to exit them completely. On an Apple product, double press the home button to bring up all active applications and exit from there.

    Re: How can I get the best out of my battery life?
    Hi,
    When I make phone calls people on the other end have difficulty hearing me. They describe as they can hardly hear me as if I was speaking through the pillow etc). I am not touching any buttons and obviously it is not mute. This was happening couple of time in June, then every now and then. Recently it happened a few time in 2 weeks. I was trying to check if it was a reception issue but the place I spoke from is my office I make 70% of phone calls from. Can you book time for me in repair shop and address the issue.
    Thank you.
    Sergey Sinitsyn

  • How do I get a disc out of my super drive when I forgot to eject it from the drive before pulling out the USB cable ?

    how do I get a disc out of my super drive when I forgot to eject it from the drive before pulling out the USB cable ?

    How force eject disc: Apple Support Communities
    Mac Mini: Eject DVD Apple Support Communities

  • How do you get your iphone out of the connect to itunes screen?

    How do you get your iphone out of the connect to itunes screen?

    What error message is it displaying? Check this Apple support document for information on specific error messages when restoring the iPhone. http://support.apple.com/kb/ts1275

  • How can i get HD video out from the lumia 900. ? ...

    How can i get HD video out from the lumia 900. ? Is there some kind of gable. ? N8 has HD cable port..so where is lumia`s port. ?

    Download Zune and start it, when started connect your Lumia 900 and you can now transfer mediafiles from the Lumia to your PC through a USB connection. For Mac use the Mac connector.
    Press the 'Accept As Solution' icon if I have solved your problem, click on the Star Icon below if my advice has helped you!

  • I left a dvd in my macbook pro for a while and now my computer wont recognize that there is even a disk in there, nor will it eject it. how do i get the dvd out?

    i left a dvd in my macbook pro for a while and now my computer wont recognize that there is even a disk in there, nor will it eject it. how do i get the dvd out?

    Hold down the mouse button or trackpad clicker as you start up.
    If no joy, restart and hold the Option key. This brings up the Startup Manager, which will draw an Icon for each bootable Volume. When all are drawn, the Eject key is "live".

  • I inserted  SD card into CD slot how do I get it back out

    Inadverdently inserted SD card into CD slot how do I get it back out help please

    Happened to me too. Just before I went on holiday and I was clearing off my SD card for my camera. I left it there until I got back (having to buy a new card at the airport) then did a quick search. Found this clip on youTube featuring an L-shaped piece of cardboard trick which worked perfectly for me on second attempt.
    You've got to really blame Apple for the design of the machine when you consider the sheer amount of people who have made this mistake. At least I won't make it again.
    J

  • How do I get the pictures out of my iPhone 4s and save it to my PC?

    How do I get the pictures out of my iPhone 4s and save it into my PC?

    Hello i-am-big-david,
    On a PC (Window 7) the iPhone shows as a digital camera in Windows Explorer under the computer section. You can import the photos from there. Sorry I'm not familiar with Windows 8, yet.
    Read here > http://support.apple.com/kb/HT4083

  • How can I get my data out of a crashed drive?

    I need help. Crashed hard drive. How can I get the data out?

    First have to define what a 'crashed drive' is, so we'll know how to respond.
    If you boot to an installer DVD does Disk Utility see the drive? What does it tell you about the drive?
    If the drive is showing up but not mounting it may be possible to repair it and get the data off yourself -
    But if it isn't even showing up then you may need to take it to a recovery specialist to get the data off it. This is costly and not guaranteed to always work.
    Did you replace the drive in the MBP and install a new OS on a new drive?
    Or is it still in the MBP and you are trying to recover it from there?
    One type of 'crash' is a head crash, usually caused by a impact or jarring to the drive while it is spinning which bounces the heads off the platters. This removes some of the magnetic media off the platters typically rendering it unrecoverable.
    So first priority is tell us precisely where you are with this drive, what you see, what you have tried, what the symptoms are, and what you need to accomplish.
    Rick

  • How can I get my iPhone out of landscape mode and back to portrait?

    How can I get my iPhone out of landscape mode and back to portrait? Tilting the phone doesn't work.

    Try following - 1 by 1:-
    * make sure portrait lock is not on & try turning on/off several times
    * turn off mobile and turned it back on
    * hard reset by pressing lock and home at same time
    If problem persist, you need to try following but be careful since the following impact your iphone.
    * resetting all setting: this will reset all settings of your iphone back to factory setting
    * resetting all setting by erasing all data: this will reset all setting and erase all data so do back-up and proper syncing and read relevant details
    * restoring from itunes: this will also erase all data and take mobile back to day 1
    last 3 options are last resort and only be done if you are sure you can restore your data.
    Please don't hold me responsible for any data loss while doing last 3 options
    Cheers!

  • How can  I get rejected photos out of LR5 and off the HD?

    When I try to deleted rejected photos in LR5 on my iMac, I get a dialog saying they can't be sent to the trash.  How can I get unwanted photos out of LR5 and off the hard drive?

    Instead of hitting just the delete key, you need to hit ⌘+Del and one of the choices will be to remove from hard drive.

  • How can I get more sound out of the Mini?

    How can I get more sound out of theMini?

    Via the headphone jack. That also provides a digitial audio out too. See:
    http://support.apple.com/kb/HT5539

  • How can i get my email out of the file box icon?

    How can I get my email out of the file box icon? Sometimes I touch it by accident and the email message goes in there.

    Another thing to try is renaming it with a .htm or .html extension.
    If that doesn't work either, do you have any other files from your old system? In particular, if you have your old places.sqlite file, you could use that to overwrite your new places.sqlite (bookmarks+history) file.

Maybe you are looking for