Java Reference
In-Depth Information
package JavaDatabaseBible.ch17.Xbeans;
import java.io.*;
import java.sql.*;
import javax.sql.*;
import org.Xbeans.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Parse an xml document and insert into a database table using a
* PreparedStatement
*/
public class SQLInsertBean extends JavaDatabaseBible.ch17.Xbeans.XBean{
static String moreoverUrl =
"http://www.moreover.com/cgi-local/page?o=xml&query=top+stories";
private static String dbUserName = "sa";
private static String dbPassword = "dba";
Connection con = null;
PreparedStatement pstmt = null;
public SQLInsertBean(){
}
public Document processDocument(Document doc) throws XbeansException {
prepareStatement();
Element root = doc.getDocumentElement();
NodeList articles = root.getElementsByTagName("article");
for(int i=0;i<articles.getLength();i++){
Element article = (Element)articles.item(i);
insertHeadline(getValues(article));
}
closeConnection();
return doc;
}
private String[] getValues(Element article){
String[] values = new String[11];
Search WWH ::




Custom Search