import org.w3c.dom.*;
l.parsers.*;
l.transform.*;
l.transform.stream.StreamResult;
l.transform.dom.DOMSource;
import java.sql.*;
import java.io.File;
public class database {
public static void main(String[] args) {
String url="jdbc:odbc:myds";
String user="sa";
String password="sa";
Connection conn;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection(url,user,password);
Statement ateStatement();
ResultSet uteQuery("select * from students");
if(rst!=null)
{
writeXML(rst);
}
else
{
System.out.println("数据库中没有数据");springboot原理通俗
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void writeXML(ResultSet rst)
{
ResultSet set=rst;
boolean flag;
try{
DocumentBuilderFactory wInstance();
DocumentBuilder wDocumentBuilder();
Document wDocument();
Element ateElement("students");
document.appendChild(rootElement);
())
{
Element ateElement("students");
rootElement.appendChild(sElement);
Element ateElement("name");
element.String("name")));
sElement.appendChild(element);
ateElement("sex");
element.ateTextNode("sex"));
sElement.appendChild(element);
ateElement("age");
element.String("age")));
sElement.appendChild(element);
}
flag=SaveXmlFile(document,"l");
if(flag)
{
System.out.println("文件创建成功");
}
else
{
System.out.println("文件创建失败");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static boolean SaveXmlFile(Document document,String filename)
{
boolean flag=true;
try{
TransformerFactory wInstance();
Transformer wTransformer();
DOMSource source=new DOMSource(document);
StreamResult result=new StreamResult(new File(filename));
}
catch(Exception e){
flag=false;
e.printStackTrace();
}
return flag;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。