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;
}
}
最近下载更多
最近浏览更多
3334004690 LV11
2024年5月27日
WHY-small LV15
2023年12月29日
ycmyyt LV2
2023年6月6日
qq1154180193
2023年5月21日
暂无贡献等级
2002-GRIT LV2
2023年5月19日
月光skr LV4
2023年4月9日
Gin19960217 LV4
2023年3月28日
aslyyds LV2
2023年1月28日
微信网友_6270418622812160 LV3
2022年12月21日
呵呵哈哈哈 LV10
2022年9月25日

