当前位置: 技术问答>java相关
在xml中增加一个节点的问题
来源: 互联网 发布时间:2015-10-11
本文导语: Document dataDoc = null; try { //Create the document builder DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docbuilder = dbfactory.newDocumentBuilder(); ...
Document dataDoc = null;
try {
//Create the document builder
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Create the new document(s)
dataDoc = docbuilder.newDocument();
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
Connection db = null;
Statement statement = null;
ResultSet resultset = null;
ResultSetMetaData resultmetadata = null;
Element dataRoot = dataDoc.createElement("visit");
try {
String strConn="jdbc:mysql://localhost/log";
String strDriver="org.gjt.mm.mysql.Driver";
String db_usr="root";
String db_password="mysql";
Class.forName(strDriver).newInstance();
db = DriverManager.getConnection(strConn,db_usr,db_password);
statement = db.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
resultset = statement.executeQuery("select * from visit");
resultmetadata = resultset.getMetaData();
int numCols = resultmetadata.getColumnCount();
while (resultset.next())
{
Element rowEl = dataDoc.createElement("row");
for (int i=1; i
try {
//Create the document builder
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Create the new document(s)
dataDoc = docbuilder.newDocument();
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
Connection db = null;
Statement statement = null;
ResultSet resultset = null;
ResultSetMetaData resultmetadata = null;
Element dataRoot = dataDoc.createElement("visit");
try {
String strConn="jdbc:mysql://localhost/log";
String strDriver="org.gjt.mm.mysql.Driver";
String db_usr="root";
String db_password="mysql";
Class.forName(strDriver).newInstance();
db = DriverManager.getConnection(strConn,db_usr,db_password);
statement = db.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
resultset = statement.executeQuery("select * from visit");
resultmetadata = resultset.getMetaData();
int numCols = resultmetadata.getColumnCount();
while (resultset.next())
{
Element rowEl = dataDoc.createElement("row");
for (int i=1; i