[英]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. 我在应用程序中使用GENERATE_UNIQUE()创建ID。 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)
. 当我从表行创建POJO对象时,我使用rs.getBytes("ID")
,当我将其写回到表中时,我使用ps.setBytes(object.getID)
。 According to comments to this question: How to use value generated by GENERATE_UNIQUE() function as foreign key? 根据对该问题的评论: 如何将GENERATE_UNIQUE()函数生成的值用作外键?
But during the POJO lifecycle I need a String
representation of an ID. 但是在POJO生命周期中,我需要ID的String
表示形式。 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. 我可以维护将ID存储为String
第二个属性,但是正在寻找一种解决方案,可以在不丢失数据的情况下将byte[]
转换为String
并返回。 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[]
数组与初始byte[]
数组不同。
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 我可以建议http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html
static byte[] parseBase64Binary(String lexicalXSDBase64Binary)
and 和
static String printBase64Binary(byte[] val)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.