日期:2014-05-16 浏览次数:20392 次
package org; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.dTx.CreateXmlFile; /** * @author Der * @Email uidin@163.com * @date 2007-4-16 * @packeage_name org * */ public class Testxml { /** * @param args * @throws ClassNotFoundException * @throws SQLException */ public static void main(String[] args) throws ClassNotFoundException, SQLException { /**加载mysql驱动*/ Class.forName("org.gjt.mm.mysql.Driver"); /**连接地址*/ Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/db_name","db_username","db_password"); Statement stmt=conn.createStatement(); /**查询语句_例句*/ ResultSet rs=stmt.executeQuery("select * from user"); /**将结果集中的数据写到指定的xml中,注意:此xml路径在当前工程的根目录*/ CreateXmlFile createXml = new CreateXmlFile(rs,"user.xml"); /**设置根元素名称*/ createXml.setRootElementName("userinfo","user"); /**创建属性名,1表示该字段在该数据表的第几列*/ createXml.setAttributeName("id",1); /**创建元素名,4表示username在该表的第4列*/ createXml.setElementName("username",4); /**开始创建xml文件*/ createXml.startCreateXml(); /** * 生成的xml样例 * <?xml version="1.0" encoding="GB2312"?> * * <userinfo> * <user id="402881e5174e8a1f01174e8aeff20001"> * <username>java</username> * </user> * </userinfo> * */ } }