很奇怪的写xml问题,我是用jdom把数据从oracle读写到ftp的xml文件上,在单机测试的时候正常,但是当放到服务器上运行的时候,就会出现生成的xml文件不正常,出现最后的地方标签不全,就是一种未写完的现象,请问是什么问题,怎样解决?(BS:数据大概是一次2000-3000条)
大致代码如下:private boolean WriteXML(String date, String filename) { String sql = "select id,sort_id,name,et,retail_price,unit_id,Specification,add_time,info_from from web_price "
+ "where add_time = to_date('" + date + "','yyyy-mm-dd')"; Connection pcon = null;
PreparedStatement pstm = null;
ResultSet rs = null; Element root, father, id, sort_id, name, et, retail_price, unit_id, specification, add_time, info_from; // Generated root element: RESULT
root = new Element("RESULT");
// Subgraph node element
father = new Element("VALUE");
id = new Element("ID");
sort_id = new Element("SORT_ID");
name = new Element("NAME");
et = new Element("MARKET");
retail_price = new Element("RETAIL_PRICE");
unit_id = new Element("UNIT_ID");
specification = new Element("SPECIFICATION");
add_time = new Element("ADD_TIME");
info_from = new Element("INFO_FROM"); // Root element will be implanted in the document doc
Document doc = new Document(root);
String infostr = ""; try {
pcon = ConnectionFactory.getConnectionFactory();
pstm = pcon.prepareStatement(sql);
rs = pstm.executeQuery();
Properties pro = new Properties();
pro.load(new FileInputStream(new File("unit.properties"))); while (rs.next()) { // Set content
id.setText(rs.getLong("id") + "");
sort_id.setText(rs.getString("sort_id"));
name.setText(rs.getString("name"));
et.setText(rs.getString("et"));
retail_price.setText(rs.getDouble("retail_price") + "");
unit_id.setText(rs.getInt("unit_id") + "");
specification.setText(rs.getString("Specification"));
add_time.setText(rs.getDate("add_time") + "");
infostr = rs.getString("info_from");
if (!infostr.equals("null")) {
info_from.setText(infostr);
} else {
info_from.setText("");
} father.addContent(id);
father.addContent(sort_id);
father.addContent(name);
father.addContent(et);
father.addContent(retail_price);
father.addContent(unit_id);
father.addContent(specification);
father.addContent(add_time);
father.addContent(info_from);
root.addContent(father);
} } catch (SQLException e) {
logger.error(e.getMessage() + "SQLException");
System.out.println("查询语句发生错误");
} catch (FileNotFoundException e) {
logger.error(e.getMessage() + "FileNotFoundException");
System.out.println("找不到unit.properties");
} catch (IOException e) {
logger.error(e.getMessage() + "IOException");
System.out.println("输出错误");
} Format format = Format.getCompactFormat();
// Set of characters for xml document utf-8
format.setEncoding("utf-8");
// Indent settings xml file for the two spaces
format.setIndent("  ");
// Elements shrink wrap a layer of elements of the two-frame
XMLOutputter XMLOut = new XMLOutputter(format);
try {
XMLOut.output(doc, new FileOutputStream(filename));
} catch (FileNotFoundException e) {
logger.error(e.getMessage() + "FileNotFoundException");
System.out.println("找不到文件名为:" + filename);
} catch (IOException e) {
logger.error(e.getMessage() + "IOException");
System.out.println("输出文件:" + filename + "错误");
} finally {
ConnectionFactory.close(pcon, pstm, rs);
}
return true;
}

解决方案 »

  1.   

    写xml文件,其实不要用任何包,自己连接字符串就可以了可能是内容太多,jdom占用太多内存,也可能别的异常
    “读写到ftp的xml文件上”是什么样的流程?
      

  2.   

    我开始的时候也是自己拼接标签的,情况也是一样,最后有人提议我可能是写标签的问题,我就改为用jdom写,但是情况仍是这样,写到ftp是公司的一个接口,具体是怎么实现的不是很清楚- -|| 我把那一段调用都贴出来吧:FTPConnectorBK fUp;
    try {
    fUp = new FTPConnectorBK(pro.getProperty("ftpHost"), Integer.parseInt(pro.getProperty("ftpPost")), pro.getProperty("ftpId") , pro.getProperty("ftpPassword"));
    fUp.login();
    fUp.upFile(DataController.class.getClassLoader().getResource("").toString().substring(6)+"xml\\price" + date.replace("-", "") + ".xml", "/price" + date.replace("-", "") + ".xml");
    fUp.logout();

    } catch (Exception e) {
    logger.error(e.getMessage() + "ftp error");
    return false;
    }
      

  3.   

    分两步测试,ftp上传大文件数据是否正常,本地写xml大文件是否正常
      

  4.   

    写本地正常 写ftp出现问题
      

  5.   

    你确定你们公司的ftp上传接口没有问题?
      

  6.   

    不妨先用jdk提供的api直接上传ftp试试