Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » WebService/XML/JSON/SOAP/SOA  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:请问这种XML该怎么读? [Re:focus]
focus





发贴: 42
积分: 2
于 2006-07-27 21:40 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢大虾提示!
已搞定。
需要下载三个包:
1.dom4j-1.6.1.jar
2.jaxen-full.jar
3.saxpath.jar
然后添加到工程中去。
我的代码:

package jp.co.smile.common;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Department {

public Department() {

}

public static String getDepartment(String departid) {

StringBuffer optionList = new StringBuffer();

//SQL文
String statement = "SELECT DEPARTMENT_NAME, DEPARTMENT_ID " +
"FROM DEPARTMENT " +
"ORDER BY DEPARTMENT_ID" ;

try {

//Oracle的连接
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@192.168.0.165:1521:jxsf";

String user = "smile";
String password = "smile";
Connection conn = DriverManager.getConnection(url,user,password);
if(conn != null){

System.out.println("Connection Success"+conn);
}else{

System.out.println("Connection failed"+conn);
}

Statement stmt = conn.createStatement();

//SQL的执行
ResultSet result = stmt.executeQuery(statement);

//提交
conn.commit();

if (departid.trim().length() != 0) {

Map departTemp = new HashMap();
String departNm = null;

while (result.next()) {

departTemp.put(result.getString("DEPARTMENT_ID"), result.getString("DEPARTMENT_NAME"));

}

Iterator iteratr = departTemp.keySet().iterator();

Iterator iteratr2 = departTemp.keySet().iterator();

while (true) {

if (iteratr.next().equals(departid)) {

departNm = departTemp.get(departid).toString();
break;
}

}

optionList.append("<option value='" + departid + "'>" + departNm + "</option>");
optionList.append("<option value=''> </option>");

while (iteratr2.hasNext()) {

String deid = iteratr2.next().toString();

if (!deid.equals(departid)) {

optionList.append("<option value='" + deid + "'>" + departTemp.get(deid).toString() + "</option>");

}
}

} else {

optionList.append("<option value=''> </option>");

while (result.next()) {

optionList.append("<option value='" + result.getString("DEPARTMENT_ID") + "'>" + result.getString("DEPARTMENT_NAME") + "</option>");

}
}

conn.close();

} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}

return optionList.toString();
}

public static void main(String[] args) {
SAXReader reader = new SAXReader();
try {
Document doc = reader.read(new File("E:\\SWECTool\\bea\\user_projects\\domains\\default\\config.xml"));
Element connPoolEle = (Element) doc.selectSingleNode("/Domain/JDBCConnectionPool");
String url = connPoolEle.attributeValue("URL");
System.out.println(url);
} catch (DocumentException e) {

e.printStackTrace();
}

}

}

成功输出:jdbc:oracle:thin:@192.168.0.165:1521:jxsf
谢谢,呵呵。


{ one point for follow-up -- why }


why edited on 2006-07-28 11:05


有了Swing为什么还要SWT?

话题树型展开
人气 标题 作者 字数 发贴时间
14607 请问这种XML该怎么读? focus 3500 2006-07-27 13:53
12155 Re:请问这种XML该怎么读? zcjl 342 2006-07-27 15:07
12426 Re:请问这种XML该怎么读? focus 373 2006-07-27 20:28
12580 Re:请问这种XML该怎么读? focus 3765 2006-07-27 21:40
13045 Re:请问这种XML该怎么读? zcjl 11 2006-07-28 09:54

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923