利用JDOM操纵XML文件(数据库连接)
2008-05-22 13:41
323 查看
利用JDOM操纵XML文件(数据库连接)
import java.io.IOException;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.*;
import java.util.*;
import org.jdom.output.*;
import java.io.*;
public class TestJDom {
public TestJDom() {
}
public static void main(String[] args) throws Exception {
TestJDom d = new TestJDom();
d.writeDb();
}
public void writeDb() throws IOException {
Document doc = new Document();
Element root = new Element("数据库");
Element driver = new Element("driver");
driver.setText("sun.jdbc.odbc.JdbcOdbcDrver");
Element uri = new Element("uri");
uri.setText("jdbc:odbc:db");
Element userName = new Element("userName");
userName.setText("sa");
Element passWord = new Element("passWord");
passWord.setText("sa");
root.addContent(driver);
root.addContent(uri);
root.addContent(userName);
root.addContent(passWord);
doc.setRootElement(root);
XMLOutputter out = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setEncoding("GB2312");
out.setFormat(format);
out.output(doc,new FileOutputStream("c:/db.xml"));
}
public void readJdom() throws Exception {
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build("c:/tt.xml");
Element root = doc.getRootElement();
List list = root.getChildren();
System.out.println(root.getChild("student").getValue());
for (int i = 0; i < list.size(); i++) {
Element ele = (Element)list.get(i);
System.out.println(ele.getName()+" "+ele.getValue());
}
}
}
import java.io.IOException;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.*;
import java.util.*;
import org.jdom.output.*;
import java.io.*;
public class TestJDom {
public TestJDom() {
}
public static void main(String[] args) throws Exception {
TestJDom d = new TestJDom();
d.writeDb();
}
public void writeDb() throws IOException {
Document doc = new Document();
Element root = new Element("数据库");
Element driver = new Element("driver");
driver.setText("sun.jdbc.odbc.JdbcOdbcDrver");
Element uri = new Element("uri");
uri.setText("jdbc:odbc:db");
Element userName = new Element("userName");
userName.setText("sa");
Element passWord = new Element("passWord");
passWord.setText("sa");
root.addContent(driver);
root.addContent(uri);
root.addContent(userName);
root.addContent(passWord);
doc.setRootElement(root);
XMLOutputter out = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setEncoding("GB2312");
out.setFormat(format);
out.output(doc,new FileOutputStream("c:/db.xml"));
}
public void readJdom() throws Exception {
SAXBuilder sb = new SAXBuilder();
Document doc = sb.build("c:/tt.xml");
Element root = doc.getRootElement();
List list = root.getChildren();
System.out.println(root.getChild("student").getValue());
for (int i = 0; i < list.size(); i++) {
Element ele = (Element)list.get(i);
System.out.println(ele.getName()+" "+ele.getValue());
}
}
}
相关文章推荐
- 利用ASP连接各种数据库
- 在VC++中利用ADO连接数据库(附带模块下载链接)
- 连接数据库和相关数据库操作——之我的方法 利用OLEDB
- python 利用pymssql连接MSSQL数据库,简单示例
- android-----利用JDBC连接服务器数据库
- 利用ASP连接各种数据库
- JAVA读取XML文件并利用该文件对数据库进行配置操作
- VS利用ADO连接数据库的操作
- ADO第一次亲密接触(转贴,内容主要是利用ADO连接数据库的方法)
- 利用ADO连接数据库
- Asp.Net连接Oracle数据库的通用操作类并且利用它对数据库查询、汇总、更新等操作演示
- 利用DataSet实现XML文件与数据库文件交换
- java利用jdbc连接数据库之插入数据
- R利用RJDBC包连接数据库
- java学习之在myclipse中利用jdbc连接数据库
- mysql利用hibernate连接数据库出错
- 利用ADO.NET连接Excel数据库,并执行相应的操作
- Asp.Net连接Oracle数据库的通用类orahelper.cs并且利用它对数据库查询、汇总、更新等操作演示
- 在Web.config中配置数据库连接(利用抽象工厂方便更换数据库)
- 利用oracle instant client,不安装客户端使用plsql远程连接数据库