将StreamResult转换为CLOB:Java

时间:2018-12-05 14:39:49

标签: java java-8

我正在从Oracle中读取CLOB列,其内容是XML文件。

<msa:data>
<msa:supplier_code>TP-0000005098</msa:supplier_code>
<msa:supplier_name>XYZ</msa:supplier_name>
</msa:data>

现在,我的目标是修改 supplier_name 元素以使其表示ABC并将该XML存储回数据库。

我已经编写了以下代码来实现相同的目的。

Clob xmlClob = SupplierDao.getByCode("TP-0000005098");
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(xmlClob.getAsciiStream());
NodeList dataList = doc.getElementsByTagName("msa:supplier_name");
dataList.item(0).setTextContent("ABC");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source source = new DOMSource(doc);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Result result = new StreamResult(outputStream);
transformer.transform(source, result);

现在,我想再次将StreamResult转换回Clob(java.sql.Clob)对象,以将其存储回数据库。我该如何实现?

0 个答案:

没有答案