/**
* 把把字串轉換為十六進位。
*/
public static final String bytesToHexString(byte[] bArray) {
StringBuffer sb = new StringBuffer(bArray.length);
String sTemp;
for (int i = 0; i < bArray.length; i++) {
sTemp = Integer.toHexString(0xFF & bArray[i]);
if (sTemp.length() < 2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}
return sb.toString();
}
sqlserver中 用CONVERT(varbinary,bf.applyType) // 把bf.applyType轉為十六進位,它前面有0x
故 CONVERT(varbinary,bf.applyType) = 0x"+bytesToHexString(busiFlowDTO.getApplyType().getBytes()));
--------------------------------------------------------------------------------------------------------------------------------------
/**
* 把把字串轉換為unicode。
*/
private String convert(String str)
{ String tmp; StringBuffer sb = new StringBuffer(1000);
char c; int i, j; sb.setLength(0);
for(i = 0;i<str.length();i++){
c = str.charAt(i);
if (c > 255) { sb.append("//u");
j = (c >>> 8); tmp = Integer.toHexString(j);
if (tmp.length() == 1) sb.append("0");
sb.append(tmp); j = (c & 0xFF); tmp = Integer.toHexString(j);
if (tmp.length() == 1) sb.append("0");
sb.append(tmp); } else { sb.append(c); }
}return(new String(sb));
}