ITeye博客

DOM读取XML 文件,连接数据库

eneve520 · 2009-06-18 16:06 · XML · 非技术 · DAO · JDBC · XML · Microsoft · Markdown

- - - com.microsoft.jdbc.sqlserver.SQLServerDriver sa sa - jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=pubs - package com.ray.xmldao.dao; import java.io.*; import org.w3c.dom.*; import org.xml.sax.SAXException; import javax.xml.parsers.*; /** * 功能:DOM解析xml文件 * 时间:2009年6月14日 * @author Ray * @version 1.0.0 * */ public class XmlDBReader { public DBProperty getXML(){ long lasting = System.currentTimeMillis(); DBProperty dbproperty = new DBProperty(); try { //得到DOM解析器的工厂实例 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //从DOM工厂获得DOM解析器 DocumentBuilder builder = factory.newDocumentBuilder(); //解析的xml文档转化为输入流,以便DOM解析器解析 File file = new File("/xml/database.xml"); //解析xml文档的输入流,得到一个Document Document doc = builder.parse(file); //得到xml文档的节点 NodeList nodelist = doc.getElementsByTagName("datasource"); for(int i=0;i

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。