package saxparse;
import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import saxparse.Article;
import saxparse.dbhelper;
public class Saxparse {
public static void main(String[] args) throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser parser = factory.newSAXParser();
Myhandler handler = new Myhandler();
parser.parse("dblp.xml", handler);
List<Article> articles = handler.getArticles();
dbhelper dbHelper = dbhelper.getDbHelper();
for (Article article : articles) {
String sql ="insert into [article_3] (author,title,pages,year,volume,journal,number,ee,url) values ('"+article.getAuthor()+"','"+article.getTitle() +"','"+article.getPages()+"','"+article.getYear()+"','"+article.getVolume()+"','"+article.getJournal()+"','"+article.getNumber()+"','"+article.getEe()+"','"+article.getUrl()+"')";
dbHelper.executeUpdate(sql);
}
dbhelper.close();
} catch (ParserConfigurationException | SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package saxparse;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
i