国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java、XML與數據庫編程實踐 (二)

2019-11-18 10:48:43
字體:
來源:轉載
供稿:網友

  文件DbxmlParser.java封裝了對xml文件的操作。
  
  import javax.xml.parsers.*;
  
  import org.w3c.dom.*;
  
  import org.xml.sax.*;
  
  import java.io.*;
  
  public class DbXmlParser
  
  {
  
    static String xmlfile;
  
    public DbXmlParser(String filename)
  
    {
  
      xmlfile=filename;
  
    }
  
    public static Element loadDocument()
  
    {
  
      try
  
      {
  
        //工廠
  
        DocumentBuilderFactory dcfactory=DocumentBuilderFactory.newInstance();
  
        //文檔構造器
  
        DocumentBuilder db=dcfactory.newDocumentBuilder();
  
        //構造的文檔
  
        Document doc=db.parse(xmlfile);
  
        //根元素
  
        Element root=doc.getDocumentElement();
  
        return root;
  
        }catch( ParserConfigurationException e){
  
        System.out.  
        e.printStackTrace();
  
      }catch(IOException e)   {
  
        System.out.println("IOException ");
  
        e.printStackTrace();
  
      }catch(SAXException e)   {
  
        System.out.println("SAXException ");
  
        e.printStackTrace();
  
      }catch(Exception e) {
  
        e.printStackTrace();
  
      }
  
      return null;
  
    }
  
    public ConnPara getSource()
  
    {
  
      Element root=loadDocument();
  
      if( root==null) { return null;  }
  
      NodeList nodes=root.getElementsByTagName("source");
  
      if(nodes.getLength()>0)
  
      {   
  
        Node node=nodes.item(0);
  
        String connclass=getChildElementValue(node,"class");
  
        String url=getChildElementValue(node,"url");
  
        String username=getChildElementValue(node,"user");
  
        String pass
Word=getChildElementValue(node,"password");
  
        return new ConnPara(connclass,url,username,password);
  
      }
  
      return null;   
  
    } 
  
    public ConnPara getDest()
  
    {
  
      Element root=loadDocument();
  
      if( root==null) return null;
  
      NodeList nodes=root.getElementsByTagName("dest");
  
      if(nodes.getLength()>0)
  
      {   
  
        Node node=nodes.item(0);
  
        String connclass=getChildElementValue(node,"class");
  
        String url=getChildElementValue(node,"url");
  
        String username=getChildElementValue(node,"user");
  
        String password=getChildElementValue(node,"password");
  
        return new ConnPara(connclass,url,username,password);
  
      }
  
      return null;   
  
    }
  
    //得到子元素的值
  
    private String getChildElementValue(Node node,String suBTagName)
  
    {
  
        String returnString = "";
  
        if(node !

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江川县| 商丘市| 南宫市| 天峨县| 鄂尔多斯市| 全南县| 闽侯县| 遵化市| 枞阳县| 北碚区| 施甸县| 明光市| 富锦市| 甘泉县| 萝北县| 黑水县| 四川省| 喀喇沁旗| 布拖县| 隆安县| 田阳县| 阿图什市| 汉阴县| 庆安县| 鄂托克前旗| 富宁县| 开化县| 桑植县| 米泉市| 塘沽区| 邢台市| 西乡县| 广水市| 九江县| 北辰区| 宿州市| 佛山市| 嘉峪关市| 黄骅市| 黑龙江省| 铅山县|