public static String getConnString(String dbAttribute)
{
String result = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("connstring.xml");
doc.normalize();
Element elm = doc.getDocumentElement();
NodeList nodes = elm.getElementsByTagName(dbAttribute);
//
for(int i=0;i<nodes.getLength();i++)
{
Element node = (Element)nodes.item(i);
result = node.getElementsByTagName("connstring").item(0).getFirstChild().getNodeValue().toString();
}
nodes=null;
elm=null;
doc=null;
builder=null;
}
catch (Exception e){
}
finally{
factory=null;
}
return result;
}
//执行这个函数,大概需要2秒的时间
//我一直注释到Document doc = builder.parse("connstring.xml")这行代码,执行速度才比较快一些
//Java读取xml没这么慢吧?或者我用的这种方法速度比较慢?
很大的话改用sax试试吧
大小为1k...
机器为dll 的D630
1G内存,cpu为Intel(R) Core(TM) 2 Duo T7250 2.00GHZ装的win 2003,tomcat 6.0
那速度应该飞起来了呀@&#(¥*@……¥(*#……@¥*