I have a simple java swing application which interacts with a sqlite database through the spring JdbcTemplate. The problem appears when trying to dump an excel document to one table in the database, the batchUpdate
methods takes a lot of time, around 40 secs for 300 excel rows. My configuration is this
The DAO class
public int[] addAll(List<Pedido> p) {
int[] a = jdbcTemplate.batchUpdate("Insert into producto values(?,?,?)", new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Pedido ped = p.get(i);
ps.setString(1, ped.getCodigo());
ps.setDouble(2, ped.getPrecio());
ps.setString(3, ped.getNombre());
}
@Override
public int getBatchSize() {
return p.size();
}
});
return a;
}
My configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.sqlite.JDBC" />
<property name="url" value="jdbc:sqlite:toruso.sqlite" />
<property name="initialSize" value="1" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
<bean id="pedidoDAO" class="toruso.model.DAO.PedidoDAOImplementation">
<property name="jdbcTemplate" >
<ref local="jdbcTemplate"/>
</property>
</bean>
</beans>
My Spring loader class
public class MainFrame extends javax.swing.JFrame {
private ClassPathXmlApplicationContext springContext;
PedidoDAO pedidoDao;
public MainFrame() {
initComponents();
this.initSpringContainer();
}
public void initSpringContainer() {
String[] contextPaths = new String[]{"configuration/appConf.xml"};
springContext = new ClassPathXmlApplicationContext(contextPaths);
BeanFactory factory = this.springContext;
this.pedidoDao = (PedidoDAO) factory.getBean("pedidoDAO");
}