利用Java代码把oracle的blob字段内容解析成XML格式的字符串

 

利用Java代码把oracle的blob字段内容解析成XML格式的字符串.

Statement statement = conn.createStatement();
				sql = " select b.fjbh,b.ws_template_id,b.multimedia from a,b_blob b where "+condition ;
	            ResultSet resultSet = statement.executeQuery(sql) ;
	            
	            while (resultSet.next()) {
		            String fjbh = resultSet.getString(1);
					Blob blob = null;
				    InputStream is = null;
				    String distFile = "d:\\xml\\"+fjbh+".xml";
				    OutputStream os = new FileOutputStream(distFile);
				    blob = (Blob) resultSet.getBlob(3);
				    is = blob.getBinaryStream();

				    byte[] b = new byte[1024] ;
				    int len = is.read(b);
				    String newStr = "" ;
				    while (len != -1) {
				        os.write(b, 0, len);
				        newStr = newStr+new String(b,"UTF-8");
				        len = is.read(b);
				    }
				    int idx = newStr.indexOf("</PRINTDATA>");
				    newStr = newStr.substring(0, idx+12);
				    //newStr.replaceAll("[?]", "[ ]");
				    System.out.println(newStr);
				    os.flush();
				    os.close();
				    is.close();
	            }

 

 

 

 

 

 

你可能感兴趣的:(java,xml,blob,oarcle)