J2SE

Преобразование org.w3c.dom.Document в String
private String xmlDocument2Clob(Document doc) throws Exception {
    DocumentBuilderFactory domFact = DocumentBuilderFactory.newInstance();
    DOMSource domSource = new DOMSource(doc);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(domSource, result);
    return writer.toString();
}
последующая передача в виде clob (для примера приведен также blob)
PreparedStatement callableStmnt;
    callableStmnt = connection.prepareCall(strBuf.toString());
    Clob xmlClob = connection.createClob();
    xmlClob.setString(1, xmlDocument2Clob(xmlDocument));
    callableStmnt.setClob(1, xmlClob);
    callableStmnt.setBinaryStream(2, xlsFile, xlsFile.available());
Копирование объекта InputStream
1. Считываем данные потока в массив байт
private void fillInputStreamMaster(InputStream iStream) throws IOException, IOException {
        byte[] buffer = new byte[1024];
        int len;
        while ((len = iStream.read(buffer)) > -1 ) {
            this.inputStreamMaster.write(buffer, 0, len);
        }
        inputStreamMaster.flush();    
    }
2. Создаем экземпляр InputStream на основе заполненного массива
private InputStream makeInputStream(){
        return new ByteArrayInputStream(this.inputStreamMaster.toByteArray()); 
}
Передача объекта в поле blob
public boolean saveFile(String id, InputStream is) {
       StringBuffer strBuf = new StringBuffer();
       strBuf.append("begin insert_file(p_id => :1, ");
       strBuf.append("p_binary_data => empty_blob()); end;");
       
       PreparedStatement prepareCallableStmnt;
       try {
           prepareCallableStmnt = conn.prepareCall(strBuf.toString());
           prepareCallableStmnt.setInt(1, Integer.parseInt(id));
           prepareCallableStmnt.execute();
           
           PreparedStatement pStmt = conn.prepareStatement("select file_src from table1 where id=:1 for update");
           pStmt.setInt(1, Integer.parseInt(id));
           ResultSet lRs = pStmt.executeQuery();
           lRs.next();
           BLOB blob = ((OracleResultSet)lRs).getBLOB(1);
           OutputStream outStream = blob.getBinaryOutputStream();
           int chunk = blob.getChunkSize(); 
           byte buffer[]= new byte[chunk]; 
           int length; 
           while ((length = is.read(buffer)) != -1){
               outStream.write(buffer, 0, length);  
           }
           outStream.flush();
           outStream.close();
       } catch (SQLException e) {
           e.printStackTrace();
           return false;
       } catch (IOException e) {
        }
        return true;
   }
URLEncode строки
Ыекштп org = java.net.URLEncoder.encode(org, "UTF-8").replace("+", "%20");

Комментариев нет :