读书人

Java 备份BLOB门类的数据生成INSERT语

发布时间: 2012-11-05 09:35:12 作者: rapoo

Java 备份BLOB类型的数据生成INSERT语句可识别的字符

做数据库备份得时候,备份二进制的数据类型如BLOB类型的数据

public static String hexToString() throws Exception {

try {

? ? ? ? ? ? ? ? ? ? ? ?InputStream in = rs.getBinaryStream(1);

int b;

StringBuffer result =new StringBuffer();

while ((b = in.read()) != -1) {

String hex = Integer.toHexString(b & 0xFF);

if (hex.length() == 1) {

hex = 0 + hex;

}

result.append(hex.toUpperCase());

}

return "0x"+result.toString();

} catch (Exception e) {

throw e;

}

}

?

读书人网 >编程

热点推荐