I\'m trying to read a table from a sybase server, process the rows, and output the results to another table. (Below is my code)
The code retrieves the table pretty
I had this same problem, finally figured it out though I also was not able to find the right explanation anywhere.
The answer is that for simple un-conditioned inserts .executeBatch()
should not be used. What batch mode is doing is making lots of individual "insert into table x ..." statements and that is why it is running slow. However if the insert statements were more complex, possibly with conditions that affect each row differently, then it might require individual insert statements and a batch execution would actually be useful.
An example of what works, try the following which creates a single insert statement as a PreparedStatement (but same concept as a Statement object would require), and solves the problem of running slow:
public boolean addSetOfRecords(String tableName, Set objects) {
StringBuffer sql = new StringBuffer("INSERT INTO " + tableName + " VALUES (?,?,?,?)");
for(int i=1;i