拼接内容,生成xml

来源:互联网 发布:网贷大数据查询系统 编辑:程序博客网 时间:2024/06/05 23:45
/** * @Description: 生成xml * @return */public static boolean createXml(){sql = "select  from T";int count = 0;try {conn = ConnectionPool.getConn("emos4");pstmt = conn.prepareStatement(sql);pstmt.setLong(1, startTime);pstmt.setLong(2, endTime);rs = pstmt.executeQuery();StringBuffer buffer = new StringBuffer();System.out.println("开始拼接xml---------------------------------------------");buffer.append("<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\"?>\n");buffer.append("<openlist>\n");while(rs.next()){buffer.append("\t<BaseStatus>"+rs.getString("c700000010")+"</BaseStatus>\n");buffer.append("\t<BaseSN>"+rs.getString("c1")+"</BaseSN>\n");count++;System.out.println("count:"+count);}buffer.append("</openlist>");System.out.println("结束拼接xml---------------------------------------------");System.out.println("开始生成xml---------------------------------------------");CommonUtil.readFileByLine(buffer.toString(), System.getProperty(CommonUtil.USER_DIR) + File.separator + CommonUtil.ATTACHMENT_PATH_NAME + File.separator + CommonUtil.OPEN + "_" + TimeUtils.getCurrentDate("yyyyMMddHHmmss") + "_1_1" +".xml");System.out.println("结束生成xml---------------------------------------------");return true;} catch (SQLException e) {e.printStackTrace();return false;} finally {DbUtil.closeConnection(conn, pstmt, rs);}}

根据业务需要while(rs.next()) 这里可以自行拼接xml或其他文件。

在下面会有用到生成文件,关闭数据库连接工具类的链接。

0 0
原创粉丝点击