tag:blogger.com,1999:blog-8712770457197348465.post4475647304943620736..comments2024-03-28T01:04:16.249-07:00Comments on Javarevisited: JDBC Batch INSERT and UPDATE example in Java with PreparedStatementjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8712770457197348465.post-13706822659344960912022-01-29T07:18:55.871-08:002022-01-29T07:18:55.871-08:00Thank you, you made my day. thanks a lot for your ...Thank you, you made my day. thanks a lot for your kind comment. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-81412253024366903622022-01-27T10:14:15.870-08:002022-01-27T10:14:15.870-08:00Mr Javin saves the day yet again.I have survived m...Mr Javin saves the day yet again.I have survived many and interview and many a coding issue just having this one blog bookmarked. God bless. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-25318997052358576972016-03-22T03:02:51.322-07:002016-03-22T03:02:51.322-07:00Couple of things
1) You can get better performance...Couple of things<br />1) You can get better performance by increasing batch size. In order to store 1000 records, you should have a batch size of 100, instead of 2, which you have currently by calling executeBatch() for every even records.<br /><br />2) You should execute batch statements inside a transaction to keep your database consistent. It's possible that one or more statements in the Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86081355464654178812014-11-12T02:26:28.001-08:002014-11-12T02:26:28.001-08:00Do you know if conn.rollback(); works with MySQL ?...Do you know if conn.rollback(); works with MySQL ?<br /><br /> I've tested version 5.6 and latest Connector-J 5.1.33 and unfortunately the records that succeeded<br />are still in the database even pStatement.executeBatch() throws an exception<br /><br />I was expecting that conn.rollback() will remove the records that succeeded.<br /><br />Alexandru Mateihttps://www.blogger.com/profile/06985816697167275467noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-19255040766301975482014-02-21T07:56:43.747-08:002014-02-21T07:56:43.747-08:00May be you need to replace this:
if (c...May be you need to replace this:<br /> if (count % batchSize == 0) {<br /> pStatement.executeBatch();<br /> }<br />for this:<br /> if (count % batchSize == 0) {<br /> pStatement.executeBatch();<br /> // conn.commit();<br /> }<br />In case if you set autocomit=false.Fabriciohttps://www.blogger.com/profile/11634241515292806335noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69437888208111111962013-06-05T01:36:20.109-07:002013-06-05T01:36:20.109-07:00I think using Spring framworks and JdbcTemplate or...I think using Spring framworks and JdbcTemplate or SimpleJdbcTemplate for batch queries are more simpler example. You just need to call batchInsert() or batchUpdate() method that's it.Rakeshnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37763370212085899582013-01-02T18:43:14.384-08:002013-01-02T18:43:14.384-08:00is there any benefit using core JDBC API for runni...is there any benefit using core JDBC API for running batch update queries, I am fond of using Spring framework and almost always use JdbcTemplate to group SQL queries in batch and then run. Also executeBatch() method returns an integer array to reflect number of rows affected by this batch update queries.Anonymousnoreply@blogger.com