0

I have a process that is reading a large dataset and then inserting it into a database. I'm debating between SimpleJdbcInsert and plain old PreparedStatements.

While the former certainly seems easier....is it slower in a significant way? I was wondering if anyone had seen/done a performance comparison.

Steve
  • 4,457
  • 12
  • 48
  • 89
  • 1
    Why don't you do that performance comparison yourself? Note that given it likely uses a prepared statement internally, it will unlikely perform better than a prepared statement itself. – Mark Rotteveel Dec 21 '18 at 19:16
  • If nobody already has this information to share, then I plan to do it myself and will post my conclusion here (which will save future generations from having to do the same test). – Steve Dec 21 '18 at 19:37

1 Answers1

1

Performance for this type of operation is dependent on whether you're doing single inserts or batch inserts, and for large numbers of inserts, the difference can be quite significant.

Batch inserts send a group of inserts to the database at once, so are more efficient than sending one at a time.

You can do batch inserts either way- SimpleJdbcInsert has an executeBatch() method, while PreparedStatement uses addBatch()/executeBatch().

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • 2
    And underneath it all uses a `PreparedStatement`. So in the end it is all the same. It boils down to ease of use and taking the (small) performance hit due to some additional abstraction. – M. Deinum Dec 22 '18 at 17:44
  • 2
    Also, if you are using MySql, be sure to read https://stackoverflow.com/questions/26307760/mysql-and-jdbc-with-rewritebatchedstatements-true – GreyBeardedGeek Dec 22 '18 at 18:49