0

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();
Community
  • 1
  • 1
Anatoly
  • 5,056
  • 9
  • 62
  • 136

2 Answers2

0

Ok, I get my answer here: Java Byte Array to String to Byte Array

Community
  • 1
  • 1
Anatoly
  • 5,056
  • 9
  • 62
  • 136
0

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)

Stavr00
  • 3,219
  • 1
  • 16
  • 28