我完成了对XML文件进行数字签名的任务,该文件位于oracle数据库表中并再次插入到数据库中。我是通过三个步骤来完成的:
问题是我想要将其保存到目录文件夹中(步骤3)。这是我正在使用的代码:
private static void storeSignedDoc(Document doc) throws ClassNotFoundException, SQLException, FileNotFoundException {
// public static FileOutputStream storeSignedDoc(Document doc) {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer trans = null;
FileOutputStream fileOutputStream = null;
try {
trans = transFactory.newTransformer();
} catch (TransformerConfigurationException ex) {
ex.printStackTrace();
}
try {
Document signedXmlFileDoc = null;
String destnSignedXmlFilePath = "383_ALLA_200417_001_signed.xml";
StreamResult streamRes = new StreamResult(new File(destnSignedXmlFilePath));
// StreamResult streamRes = new StreamResult(fileOutputStream);
trans.transform(new DOMSource(doc), streamRes);
// trans.transform(new DOMSource(doc), new Result(signedXmlFileDoc));
System.out.println("fileOutputStream : " + fileOutputStream);
ClobFile cb = new ClobFile();
cb.insertClob();
} catch (TransformerException ex) {
ex.printStackTrace();
}
System.out.println("XML file with attached digital signature generated successfully ...");
// return fileOutputStream;
}//storeSignedDoc() ends here
用于检索和插入xml文件:
public InputStream getByteByClob(String query) throws ClassNotFoundException, SQLException {
Clob clob = null;
ResultSet rs = cs.connect(query);
while (rs.next()) {
clob = rs.getClob(1);
}
InputStream clobStream = clob.getAsciiStream();
return clobStream;
}
public void insertClob() throws ClassNotFoundException, SQLException, FileNotFoundException {
String query = "---UPDATE QUERY ----";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("-- AS REQUIRED --");
PreparedStatement pstmt = con.prepareStatement(query);
File f = new File("myfile_signed.xml");
FileReader fr = new FileReader(f);
pstmt.setCharacterStream(1, fr, (int) f.length());
int i = pstmt.executeUpdate();
System.out.println(i + " records affected");
con.close();
}
}
请帮我解决这个问题..