怪事情,高手帮忙讲解一哈好?
我用以下代码把一个数据库文件生成XML文件
public static void main(String[] args) {
Connection con = ConDB.Con();
PreparedStatement pst = null;
ResultSet rs = null;
String colName;
try {
pst = con.prepareStatement( "SELECT * FROM master ");
rs = pst.executeQuery();
Document document = new Document(new Element( "根元素 ")); //创建文档,并设根元素
ResultSetMetaData rsmd = rs.getMetaData(); //获取字段名,返回ResultSetMetaData对像
int numberOfColumns = rsmd.getColumnCount();
while (rs.next()) {
Element element0 = new Element( "users "); //创建元素 生成JDOM树
document.getRootElement().addContent(element0);
// Element element2 = new Element( "userphone ");
// element0.addContent(element2);
for (int i = 1; i <= numberOfColumns; i++) {
try {
colName = new String(rs.getString(i));
//构造元素节点和文本节点
Element element = new Element(rsmd.getColumnName(i)).setText(colName);
element0.addContent(element);
} catch (Exception ex1) {