简体   繁体   中英

How to convert GENERATE_UNIQUE() value to readable format from byte[] and then back to byte[]

I use in my application GENERATE_UNIQUE() to create IDs. When I create a POJO object from a table row I use rs.getBytes("ID") and when I write it back to table I use ps.setBytes(object.getID) . According to comments to this question: How to use value generated by GENERATE_UNIQUE() function as foreign key?

But during the POJO lifecycle I need a String representation of an ID. I can maintain second property to store ID as a String but looking for a solution where I can convert from byte[] to String and back without loosing data. I tried the following code in various variations but byte[] array which I get back isn't the same as an initial byte[] array.

            byte[] result = rs.getBytes("ID");
            String test = result.toString();
            byte[] test1 = test.getBytes();

好的,我在这里得到答案: Java Byte Array to String to Byte Array

May I suggest http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html

static byte[] parseBase64Binary(String lexicalXSDBase64Binary)

and

static String printBase64Binary(byte[] val)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM