我有一个程序,试图从oracle表检索不同的数据类型并将行转换为MD5哈希。
ByteArrayOutputStream sqlResultSetRow = new ByteArrayOutputStream();
ByteArrayOutputStream sqlResultSetOut = new ByteArrayOutputStream(); switch (columnType) {
case Types.NUMERIC:
String integerValue = Integer.toString(rs.getInt(col));
if(!rs.wasNull()){
sqlResultSetRow.write(integerValue.getBytes("UTF-8"), 0, integerValue.length());
}
break;
case Types.FLOAT:
String floatValue = Float.toString(rs.getFloat(col));
if(!rs.wasNull()){
sqlResultSetRow.write(floatValue.getBytes("UTF-8"), 0, floatValue.length());
}
break;
case Types.CLOB:
InputStream ins = rs.getBinaryStream(col);
if(!rs.wasNull()){
sqlResultSetRow.write(getCLOBValue(ins));
}
break;
sqlResultSetRow.writeTo(sqlResultSetOut); ComputeLNMD5Hash(new ByteArrayInputStream(sqlResultSetOut.toByteArray()))
从表中检索XML类型时,我得到的是SYS.xmltype,而不是Types.SQLXML。它们之间有什么区别,以及如何将SYS.xmltype转换为Byte [],以便可以将其写入bytearrayoutputstream以计算整个行的哈希值。
最佳答案
我是这样的:-
if(rsmd.getColumnTypeName(col).equals("SYS.XMLTYPE")){
OracleResultSet orset = (OracleResultSet) rs;
if(orset.getOPAQUE(col) != null) {
XMLType poxml = XMLType.createXML(orset.getOPAQUE(col));
sqlResultSetRow.write(poxml.getStringVal().getBytes("UTF-8"));
}
}