Today I have trouble to insert data into Postgres database using procedure. I have one procedure to insert record to it , but it is so slow with many record. Can help to fix my procedure.
void insertRecord(ArrayList<Product> pro)throws Exception{
Class.forName("org.postgresql.Driver");
con=DriverManager.getConnection("jdbc:postgresql://localhost:5433/dbStock?","rina","2001");
//con.setAutoCommit(false);
CallableStatement stmt=con.prepareCall("{call MyInsert(?,?,?,?,?)}");
for(Product p:pro){
stmt.setInt(1, p.getId());
stmt.setString(2, p.getName());
stmt.setInt(3, p.getUnitprice());
stmt.setInt(4, p.getQty());
stmt.setString(5, p.getImportedDate());
//pstm.executeUpdate();
stmt.execute();
}
//con.commit();
}
//main Method
public static void main(String[] args)throws Exception {
ArrayList<Product>pro=new ArrayList<>();
for(int i=1;i<=1_00000;i++){
pro.add(new Product(i,"coca",12,12,"2014"));
}
System.out.println("Done");
Long start=System.currentTimeMillis();
new dbObjectDriver().insertRecord(pro);
long stop=System.currentTimeMillis();
System.out.println(stop-start);
}