This program runs successfully.
It's taking 14 seconds to insert 100000 simple records of 4 columns i.e empid, empname, age, gender. How can I reduce the timing even records are complex and more than 100000 ?
Depending on the memory assigned to Java and network speed between Java and DB, batch size can be selected.
I will not set a batch size to 10 as it will do a lot of iterations between the network, and I will not set a batch size of 10000 to avoid out of memory error and this will put a lot of data in network at a time.
You can go for batch size of 500 so that it will be a balance between network iteration and avoid out of memory error.
So after every 500th addBatch(), do an executeBatch().
Again, there is no hard n fast rule, optimum-performance-batch-size can vary depending on factors.
Apologies for delay, had internet problem. Here in this example I made a batch of 5 records. After this I called executeBatch(). so
The list of commands associated with stmt will now be empty because the four commands added previously were sent to the database when stmt called the method executeBatch. You can at any time explicitly empty this list of commands with the method clearBatch.
JLS link still after inserting 5000 records means 1000 batch I'm explicitly clearing batch commands.
So after every 500th addBatch(), do an executeBatch().
do you mean after 500 records ? because what I'm thinking is
above five pstmt.addBatch() is one batch of 5 records hope I'm correct ? and inserting them once when I call executeBatch() so one batch of 5 records right ?
yes I did that still takes 14074 milliseconds. Do I have to use procedures here. I used that many moons ago but right now I don't remember its usage. will figure it out once I finish with Servlet and JSP.
Why I'm curious about this stuff is because when I was working as trainee in a company I had a client project in which I had to insert 80000- 90000 records in a table, these records were result of executing select SQL query from different tables, using batch it used to take 17 minutes something like that. By the time I could solve that the senior found the solution but I didn't how he solved. anyway if you find solution please let me know, Thank you.