'Parse Huge xml file in spring boot and load to oracle
I have a requirement to load huge xml file having 1 million records and load to the oracle table. Each record has starting and end tags as and there are many attributes for car in a record I tried the following :
XmlStreamReader=xmlInputFactory.createXmlStreamReader(file.getInputStream());
while (xmlStreamReader.hasNext())
{
xmlStreamReader.next();
if(xmlStreamReader.getEventType) == XMLStreamReader.START_ELEMENT){
if( xmlStreamReader.getLocalName.equalsIgnoreCase("car"){
Car car=new Car();
car=xmlMapper.readValue(XmlStreamReader,Car.class)
BeanUtils.copyProperties(car,carEntity);
carRepository.save(carEntity);
}
}
Note. Car POJO is annotated with the Jaxb annotations for the parsing from xml to Car object This is working fine for smaller xml but for parsing 1 million lines it's taking like a whole day.
Any suggestions how to increase the speed .Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|