Wednesday 15 February 2012

jdbc - Listening to batch queries with PreparedStatement in Java -


Let's say we have this snippet:

  dbConnection.setAutoCommit (false); // Transaction manually with the string "Let's include in DB." + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE)" + "(?,?,?,?); Place created = dbConnection.prepareStatement (insertTableSQL); {ReadyStatement.setInt (1, 101) for (Int i = 0; I & lt; 5000; i ++); ReadyStatement.setString (2, "im_a_new_user"); ReadyStatement.setString (3, "Admin"); Preparedness. Sitemapstamp (4, "00: 00: 00.000"); ReadyStatement.addBatch (); } Preparedness Exactbatch (); DbConnection.commit ();   

It basically adds 5000 batch inserts to created space and executes them.

Now, I have a GUI with JProgressBar , and I generated statement to executeBatch () call After, to know how many questions have been executed and want to hear for the progress bar to update. I already have the code to update the progress bar but I do not know how to listen to the statement made , is it possible to do this?

You can divide the entire data in bulk and treat each of them individually. And can update the progress bar later. Private Int BULKSIZE = 100; // Define your own bulk size (int j = 0; j & lt; 5000; j + = bulkseuse) {for (int i = 0; i & lt; BULKSIZE; ++ i) {ready level. SetInt (1, 101); ReadyStatement.setString (2, "im_a_new_user"); ReadyStatement.setString (3, "Admin"); Preparedness. Sitemapstamp (4, "00: 00: 00.000"); ReadyStatement.addBatch (); } Preparedness Exactbatch (); UpdateProgressBar (); }

No comments:

Post a Comment