很奇怪的写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;
}
大致代码如下: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;
}
解决方案 »
- 如何在swt desiger中实现button的清空与登录功能
- List.toArray的一个问题
- 打包jar文件失败?????
- 帮我看下一段简单的程序,谢谢
- 写文件时怎样指定从N字节开始写W长的字节~
- 用jdbc读取数据的时候,有这个警告:但是不影响读取数据
- 怎么在JAVA中实现只有让一个子类才能访问它父类的属性,用private,还是protected?
- 高分求,如何用jbuilder6.0实现多窗口操作
- 如何得到%df%DC...这样的字符??
- 请教各们高手。你们用的术语B/S,C/S是什么意思?
- 使用了未经检查或不安全的操作。应该怎么修改?
- JAVA内部匿名类中的语句块问题【先多谢高手】
“读写到ftp的xml文件上”是什么样的流程?
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;
}