This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to convert RAW(32) to String? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to convert RAW(32) to String?" Watch "How to convert RAW(32) to String?" New topic

How to convert RAW(32) to String?

liang gu
Ranch Hand

Joined: Nov 05, 2001
Posts: 89
I retrieved an Oracle RAW(32) field by
byte b[]= statement.getBytes(n).
Somehow, I need to have the String represtation of this field, and later also need to convert back to the byte[]. When I use new String(b), it just gives me some unreadable symbols. While at the same time, I know this field have a value like: A95C92500B885926E0340003BA16A687.
Thanks in advance!
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
Most likely, the byte array you are getting from the database is not the byte array you assume you are getting. With the String(byte[]) constructor, the String class assumes that each byte in the byte array is a character. Thus, if you have the byte array
[65, 66]
the constructor String(byte[]) will create the String "AB". However, the byte array could be in a different encoding, in which case you should use the constructor String(byte[], String) where the second parameter is the encoding and would correctly convert the byte array.
To help narrow down the problem: After you get the byte array, print out the value of each byte. After creating the String, use the String.getBytes() method and print out the value of each byte. Post the results here.
GeeCON Prague 2014
subject: How to convert RAW(32) to String?