<%@page contentType="text/html;charset=GBK"%>
>
用JDOM实现数据库到XML的转换
<%@page import = "org.jdom.*"%>
<%@page import = "org.jdom.output.*"%>
<%@page import = "java.*"%>
<%@page import = "java.sql.*" %>
<%@page import = "DB.*" %>
<%@ page import="java.io.*" %>
<%
String sql = null;
ResultSet rs = null;
Document document=new Document(new Element("PUSH统计"));//创建文档
int count = 1;
String sElement = "用户";
try{
DBGAMEConnection cn = new DBGAMEConnection();
sql = "SELECT * FROM tbl_wappush WHERE length(sTUID)>20 ORDER BY dPushDate";
rs = cn.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData(); //获取字段名
int numberOfColumns = rsmd.getColumnCount(); //获取字段数
while (rs.next()){
sElement = "用户" + count;
Element element0=new Element(sElement); //创建元素 生成JDOM树
document.getRootElement().addContent(element0);
for (int i=1; i<=numberOfColumns;i++)
{
String date=rs.getString(i); //代码转换
Element element=new Element(rsmd.getColumnName(i)).setText(date);
element0.addContent(element);
}
count++;
}
rs.close();
}catch (SQLException e){