I have many records,If I use "Insert(...)" in for(int i=0;i<n;i++),I find that it is very slow,how to insert many records into Mysql fast?
Printable View
I have many records,If I use "Insert(...)" in for(int i=0;i<n;i++),I find that it is very slow,how to insert many records into Mysql fast?
You can use transaction.
Code:
dbConnection.transaction(); for(int i=0;i<n;i++) { // insert record here } dbConnection.commit();
transactions are the best way, but if your DBS doesn't support them, then you (maybe) can gain speed by joining all inserts and only execute one INSERT statement.