package com.zhangjun.xml;
import java.io.PrintStream;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class AddItem
{
public void addItem(Document dom, Element row, ResultSet rs, int col, String sOrder, String sLink, int id)
{
try
{
ResultSetMetaData tz = rs.getMetaData();
String sName = tz.getColumnName(col);
String sType = tz.getColumnTypeName(col);
String sValue;
if (rs.getString(col) == null) {
sValue = "";
}
else {
sValue = toGBK(rs.getString(col).trim());
}
Element item = dom.createElement("item");
row.appendChild(item);
item.setAttribute("id", "" + id);
Element name = dom.createElement("name");
item.appendChild(name);
name.appendChild(dom.createTextNode(sName));
Element value = dom.createElement("value");
item.appendChild(value);
value.appendChild(dom.createTextNode(sValue));
Element type = dom.createElement("type");
item.appendChild(type);
type.appendChild(dom.createTextNode(sType));
Element order = dom.createElement("order");
item.appendChild(order);
order.appendChild(dom.createTextNode(sOrder));
Element link = dom.createElement("link");
item.appendChild(link);
link.appendChild(dom.createTextNode(sLink));
}
catch (Exception e)
{
System.out.println("com.zhangjun.xml.addItem rs ID:" + e);
}
}
public void addItem(Document dom, Element row, ResultSet rs, int col, String sOrder, String sLink, int id, String dbserver)
{
try
{
ResultSetMetaData tz = rs.getMetaData();
String sName = tz.getColumnName(col);
String sType = tz.getColumnTypeName(col);
String sValue = null;
if (rs.getString(col) == null) {
sValue = "";
}
else if (dbserver.equals("sql"))
sValue = toGBK(rs.getString(col).trim());
else if (dbserver.equals("oracle")) {
sValue = rs.getString(col).trim();
}
Element item = dom.createElement("item");
row.appendChild(item);
item.setAttribute("id", "" + id);
Element name = dom.createElement("name");
item.appendChild(name);
name.appendChild(dom.createTextNode(sName));
Element value = dom.createElement("value");
item.appendChild(value);
value.appendChild(dom.createTextNode(sValue));
Element type = dom.createElement("type");
item.appendChild(type);
type.appendChild(dom.createTextNode(sType));
Element order = dom.createElement("order");
item.appendChild(order);
order.appendChild(dom.createTextNode(sOrder));
Element link = dom.createElement("link");
item.appendChild(link);
link.appendChild(dom.createTextNode(sLink));
}
catch (Exception e)
{
System.out.println("com.zhangjun.xml.addItem " + dbserver + ":" + e);
}
}
public void addItem(Document dom, Element row, String title, String content, String sOrder, String sLink, int id)
{
try
{
Element item = dom.createElement("item");
row.appendChild(item);
item.setAttribute("id", "" + id);
Element name = dom.createElement("name");
item.appendChild(name);
name.appendChild(dom.createTextNode(title));
Element value = dom.createElement("value");
item.appendChild(value);
if (!(sLink.equals("HTML")))
value.appendChild(dom.createTextNode(content));
else
value.appendChild(dom.createCDATASection(content));
Element type = dom.createElement("type");
item.appendChild(type);
type.appendChild(dom.createTextNode("String"));
Element order = dom.createElement("order");
item.appendChild(order);
order.appendChild(dom.createTextNode(sOrder));
Element link = dom.createElement("link");
item.appendChild(link);
link.appendChild(dom.createTextNode(sLink));
}
catch (Exception e)
{
System.out.println("com.zhangjun.xml.addItem content:" + e);
}
}
public String toGBK(String str)
{
String strNew = new String();
try {
byte[] bbb = str.getBytes("ISO8859_1");
strNew = new String(bbb, 0, bbb.length, "GBK");
}
catch (Exception e)
{
System.out.println(e);
}
return strNew;
}
}
最近下载更多
最近浏览更多
cz8857216 LV4
2024年3月8日
fesfefe LV13
2024年1月26日
uni-code_0123 LV1
2023年11月11日
EFWAGGFAWGR
2023年10月19日
暂无贡献等级
微信网友_6467077197238272 LV1
2023年5月8日
lironggang LV38
2023年3月28日
zjc010726
2023年3月15日
暂无贡献等级
qwqw900619 LV4
2022年7月16日
nbzhou2013 LV14
2022年4月4日
一直都会顺利的小吴 LV5
2022年2月16日

