For inserts of millions of rows, I've used BULK INSERT, writing data to a CSV file that the SQL Server instance has access to. This outperforms any type of insert via JDBC, but at the cost of reduced flexibility. For smaller numbers of rows, using JDBC's Statement.addBatch()
and Statement.executeBatch()
can be used to avoid the overhead of sending many small commands.
Depending upon your requirements, you may have to put all this in one transaction, or you may be able to split up into several transactions, if full ACID guarantees for the entire data set are not required.
Here is an article discussing bulk insert of XML. I have no data to base any conclusion on, but at a guess I would imagine BULK INSERT the raw row data will be faster since there is no OPENXML transformation required. Of course, if your data is already in XML then this makes sense, but if not, then staying with tabular data is probably simplest, and possibly most performant.