Hi all - I have one xml file and now I want to load this content into a table through a jawa program and having hard time in one of the insert statement.
See the bold statement - I am not sure how to load data and save it into a table - could anyone help?
try {
File file = new File("customer.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " + doc.getDocumentElement().getNodeName());
NodeList nodeLst = doc.getElementsByTagName("customer");
System.out.println("Information of all customer");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("name");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue());
stmt.executeUpdate ("INSERT INTO customer (name, email) values ( ") + ((Node) fstNm.item(0)).getNodeValue()) + " , 'abc1@yahoo.com') ");
}
}
} catch (Exception e) {
e.printStackTrace();
}