---
title: "DOM读取XML 文件，连接数据库"
author: "eneve520"
date: "2009-06-18T16:06:01Z"
tags: ["DAO", "JDBC", "Microsoft", "XML"]
categories: ["非技术"]
slug: "dom-xml"
draft: false
lastmod: "2009-09-08T18:31:34Z"
id: 410947
url: "https://eneve520.iteye.com/blog/410947"
---

\- - - 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