aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to convert RAW(32) to String?" Watch "How to convert RAW(32) to String?" New topic
Author

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.
KMukhar
http://home.earthlink.net/~kmukhar/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert RAW(32) to String?
 
Similar Threads
Problem in converting RAW data type to String
How to get byte[] from the Image
Are the code pages in charsets.jar documented somewhere?
How to get byte[] from the Image?
How to convert binary octet string into byte array for writing into socket