I am doing XML unmarshalling using java jaxb and converting them into strings and calling the function that stores the string in a sql table. Now I want to store all of string in a list and insert them in a sql table. Based on the length of list, I ll do them bulk insert I don't want to call the table insert function everytime.I need help on modifying the code accordingly
XMLInputFactory xif = XMLInputFactory.newFactory();
Reader reader = new StringReader(response.toString());
XMLStreamReader xsr = xif.createXMLStreamReader(reader);
while(xsr.hasNext()) {
if(xsr.isStartElement() && xsr.getLocalName().equals("customer")) {
JAXBContext jc = JAXBContext.newInstance(Customer.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Customer jb = unmarshaller.unmarshal(xsr,Customer.class).getValue();
String customer_name=jb.getNAME();
String customer_id=jb.getCUSTOMERID();
String entity_id=jb.getENTITY();
System.out.println("Customer Name" +customer_name);
System.out.println("Customer ID" +customer_id);
System.out.println("Entity ID" +entity_id);
String insertStatement = "TABLEINSERT (customer_id, customer_name, entity_id)";
insertStatements.add(insertStatement);
}
xsr.next();
}
if(insertStatements.size() > 10){
TABLEINSERT (customer_id, customer_name, entity_id);
} else {
System.out.println("Nothing");
}
private static void TABLEINSERT (String CustomerID,String CustomerName, String EntityID)
{
try
{
System.out.println("Inserting....");
PreparedStatement statement = con.prepareStatement("INSERT INTO intacct_customer (customer_id,customer_name,entity_id) VALUES ( ?, ?,?)");
statement.setString(1, CustomerID);
statement.setString(2, CustomerName);
statement.setString(3, EntityID);
statement.execute();
}
catch (Exception e)
{
System.out.println(e.getMessage());
System.exit(0);
}
}