This discussion is archived
3 Replies Latest reply: Oct 15, 2012 2:49 PM by DrClap RSS

the issue about the ResultSet.TYPE_SCROLL_INSENSITIVE

968283 Newbie
Currently Being Moderated
my database is oracle ,the oracle charset is "us7ascii".and i save chinese charset in the database ,normally ,i get the data from the database ,use

Statement s =conn.createStatement();

then execute the sql, then use

new String (string.getBytes("iso-8859-1"),"gbk")

i can get the correct data.but if i use:

Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

still use:

new String (string.getBytes("iso-8859-1"),"gbk")

convert the encode,but i can't get the correct data ,the result is "?????" ,why ?
  • 1. Re: the issue about the ResultSet.TYPE_SCROLL_INSENSITIVE
    Kayaman Guru
    Currently Being Moderated
    965280 wrote:
    new String (string.getBytes("iso-8859-1"),"gbk")
    This means the following:
    Get the bytes of string out in iso-8859-1 encoding, then create a new String out of those bytes, and interpret them as GBK.

    Since GBK seems to be a variable byte encoding, you'll end up with corrupt data. What you need to do is use a proper charset in the database (such as UTF or GBK).

    Or you can hack around with incompatible encodings and end up with bugs like what you're experiencing.
  • 2. Re: the issue about the ResultSet.TYPE_SCROLL_INSENSITIVE
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!
    >
    my database is oracle ,the oracle charset is "us7ascii".and i save chinese charset in the database
    >
    Really? Please explain how that is possible.

    The US7ASCII only uses 7 bits to represent each character so can only represent 128 characters; none of them are chinese.

    Please refer to this table of ALL of the 7 bit ASCII characters and post which ones you think are chinese.
    http://www.tutorialspoint.com/html/ascii_table_lookup.htm
  • 3. Re: the issue about the ResultSet.TYPE_SCROLL_INSENSITIVE
    DrClap Expert
    Currently Being Moderated
    rp0428 wrote:
    Really? Please explain how that is possible.

    The US7ASCII only uses 7 bits to represent each character so can only represent 128 characters; none of them are chinese.
    Perhaps the sleazy hack "new String(string.getBytes())" actually works to encode and decode characters between Unicode and 7-bit ASCII -- but I haven't got the energy to figure out how it might work. My response to this sort of question is "Configure Oracle with the right character set in the first place so you don't have to deal with it at the application level".

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points