从数据库查询数据然后拼接成xml文件

<%@page import="java.util.HashSet"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.List"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="org.apache.el.lang.ExpressionBuilder"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.Out"%>
<%@page import="org.apache.tools.ant.filters.TokenFilter.Trim"%>
<%@page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.io.OutputStreamWriter"%>
<%@page import="java.io.Writer"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="java.util.regex.Matcher"%>
<%@page import="org.apache.commons.lang.StringEscapeUtils"%>
<%@ page import="com.hanweb.jcms.service.info.Jcms_InfoBLF" %>
<%@page import="com.hanweb.common.basedao.Query"%>
<%@page import="com.hanweb.jcms.dao.WebInformationDAO"%>
<%@page import="com.hanweb.common.util.SpringUtil"%>
<%@page import="com.hanweb.common.util.NumberUtil"%>
<%@page import="com.hanweb.jcms.dao.CatalogInfoDAO"%>
<%@page import=" com.hanweb.jcms.entity.Jcms_InfoEntity"%>
<%@page import= "com.hanweb.jcms.sys.service.SysInfo"%>
<%@page import="com.hanweb.jcms.constant.Tables"%>
<%@page import="com.hanweb.common.BaseInfo"%>
<%
out.clear();
try {
writexml();
for(int ii = 0; ii < 20;ii++){
out.println("********开始导出!********
");
out.println("********导出完毕!********
");
}
} catch (Exception e) {
}
%>
<%!
private static String strAppID = "1";

private static String[] colsname = { "信息标题", "创建日期","用户帐号","关键字","作者","来源",
"摘要","录入人","审核人","链接网址","截止日期","评论","信息备注","发布时间","文号","正文","附件","统一编码"};
private static String basicPath = "J:/数据测试/源数据/";
private static int infoCount = 0; //导出信息总数s
private static int cataCount = 0; //有信息的栏目数
private static String cataInfo = ""; //有信息栏目的ID集合
private static String infoEachNum = ""; //有信息栏目的信息数
private static int totalPage = 0; //xml个数
private static int totalNum = 0; //信息总数
private static int eachPage = 1000; //每个xml的信息条数
private static int xmlIndex = 0; //xml计数
private static int beginIndex = 0; //开始写的信息index
private static int endIndex = 0; //结束信息index
private static String path = "";
public static void writexml() {
String infoSql= "select count(1) from jcms_info where i_webid = 2678 and i_cataid = 1345533";
WebInformationDAO webDao = SpringUtil.getBean(WebInformationDAO.class);
Query query = webDao.createQuery(infoSql);
int total = webDao.queryForInteger(query);
int pageno = 0;
if(total/300 == 0){
pageno = total%300;
}else{
pageno = total%300 + 1;
}
for(int p = 0; p < pageno;p++){
/*"信息标题", "创建日期","用户帐号","关键字","作者","来源",
"摘要","录入人","审核人","链接网址","截止日期","评论","信息备注","发布时间","文号","正文","附件","统一编码"*/
infoSql= "select i_id, vc_title,c_createdate,‘‘,vc_keyword,vc_author,vc_source,vc_describe,vc_editor,‘‘,vc_href,‘‘,‘‘,‘‘,"+
"c_complatedate,vc_filenumber,vc_content,vc_attach,vc_sectitle "+
"from jcms_info where i_webid = 2678 and i_cataid = 1345533 LIMIT "+p*1000+","+1000;

CatalogInfoDAO cataDao = SpringUtil.getBean(CatalogInfoDAO.class);
query = cataDao.createQuery(infoSql);
System.out.println( "**************infoSql**********" + infoSql);
String[][] strDatas = cataDao.queryForArrays(query);
System.out.println("开始导出,一共有" + strDatas.length + "条信息!");
infoCount += strDatas.length;
cataCount++;

totalNum = strDatas.length;
/* if (totalNum % eachPage == 0) {
totalPage = totalNum / eachPage;
} else {
totalPage = totalNum / eachPage + 1;
} */
SysInfo sys = new SysInfo();
Jcms_InfoBLF infoBLF = Jcms_InfoBLF.getInstance().init(sys);
Jcms_InfoEntity entity;
try {
/* for (xmlIndex = 0; xmlIndex < totalPage; xmlIndex++) { */

/* beginIndex = xmlIndex * eachPage;
endIndex = (xmlIndex + 1) * eachPage > strDatas.length ? strDatas.length
: (xmlIndex + 1) * eachPage; */
StringBuffer sb = new StringBuffer();
sb.append(""
+ "\r\n");
sb.append("");
//写文件
path =BaseInfo.getRealPath() + "/info/";
//path ="f:/数据测试/目标数据";
String filePath = path + p+"info.xml";
FileOutputStream fos = new FileOutputStream(filePath,false);
Writer writer = new OutputStreamWriter(fos, "UTF-8");
writer.write(sb.toString());
sb.delete(0, sb.length());
writer.flush();
writer.close();
/* } */
} catch (Exception e) {
e.printStackTrace();
}

System.out.println("==============一共导出" + cataCount+ "个栏目==================");
System.out.println("==============一共" + infoCount+ "条信息==================");
}

}
%>

时间: 2024-08-30 01:46:38

从数据库查询数据然后拼接成xml文件的相关文章

如何将数据库中的表导成XML文件

1.现将数据库中的信息读到DataTable中 2.用函数将DataTable转为string private string ConvertDataTableToXML(DataTable dt) { if (dt != null) { MemoryStream ms = null; XmlTextWriter XmlWt = null; try { ms = new MemoryStream(); XmlWt = new XmlTextWriter(ms, Encoding.Unicode);

oracle 10g 用dbms_xmlgen将数据表转成xml格式

oracle 10g 用dbms_xmlgen将数据表转成xml格式 oracle 10g 用dbms_xmlgen将数据表转成xml格式 oracle用plsql将sql查询的所有数据导出为xml

用struts2标签如何从数据库获取数据并在查询页面显示。最近做一个小项目,需要用到struts2标签从数据库查询数据,并且用迭代器iterator标签在查询页面显示,可是一开始,怎么也获取不到数据,想了许久,最后发现,是自己少定义了一个变量,也就是var变量。

最近做一个小项目,需要用到struts2标签从数据库查询数据,并且用迭代器iterator标签在查询页面显示,可是一开始,怎么也获取不到数据,想了许久,最后发现,是自己少定义了一个变量,也就是var变量.<s:iterator>标签有一个value属性,用来存放在Action类的方法中存数据的list集合,还有一个id,好像是说指定集合的索引的意思,就是给list集合遍历出来的每个对象加上一个数字标签,反正我是这么理解的,没用过.还有一个很重要,就是var变量,我在s:iterator按ctr

C#连接Oracle数据库查询数据

C#连接Oracle数据库可以实现许多我们需要的功能,下面介绍的是C#连接Oracle数据库查询数据的方法,如果您对C#连接Oracle数据库方面感兴趣的话,不妨一看. using System; using System.Collections.Generic; using System.ComponentModel using System.Data.OracleClient;;//这行和下一行都要先在引用中填加system.data.oracleclient using System.Da

c#程序将excel文件转换成xml文件

要程序你自己去组装去,我只写两个部分,一个是读Excel的部分,然后是写入到xml的1) 从指定的excel读出信息string strConn="provider=Microsoft.Jet.OLEDB.4.0;data source=你的Excel文件.xls;Extended Properties=Excel 8.0;";DataSet ds=new DataSet();System.Data.OleDb.OleDbConnection oleConn=new System.Da

提取数据表保存为XML文件

1 //连接数据库 2 SqlConnection con = new SqlConnection("server=****;database=****;uid=sa;pwd=********"); 3 4 /// <summary> 5 /// 提取数据表保存为XML文件 6 /// </summary> 7 /// <param name="sender"></param> 8 /// <param name

如何让SQL Server数据库自动备份并压缩成rar文件

1.  先开启xm_cmdshell服务 xp_cmdshell 扩展存储过程将命令字符串作为操作系统命令 shell 执行,并以文本行的形式返回所有输出.由于xp_cmdshell 可以执行任何操作系统命令,所以一旦SQL Server管理员帐号(如sa)被攻破,那么攻击者就可以利用xp_cmdshell 在SQL Server中执行操作系统命令,如:创建系统管理员,也就意味着系统的最高权限已在别人的掌控之中.由于存在安全隐患,所以在SQL Server 2005中, xp_cmdshell

Dom4j 读取一个XML文件和将String写成XML文件

dom4j保存文件xml格式和读取XML文件内容,代码如下: package com.qmjs.imut import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import org.apache.log4j.Logger; import org.dom4j.Document; import org.dom4j.DocumentHelper; i

[转]C#反射,根据反射将数据库查询数据和实体类绑定,并未实体类赋值

本文来自:http://www.cnblogs.com/mrchenzh/archive/2010/05/31/1747937.html /***************************************** * 说明:利用反射将数据库查询的内容自动绑定 *       到实体类 * * 时间:1:49 2009-9-19 * * 程序员:王文壮 * ***************************************/ /****************数据库脚本***