Re: batch update is sporadically incomplete



Daisy wrote:
> Sporadically, the last few entries of a batch are not written. I'm
> writing to a mysql database using JDBC. Here's a short version of my
> code. Does anyone have suggestions on possible causes or other
> diagnostics?
>
> class DatabaseWriter{
>
> int writeCount=0;
>
> public DatabaseWriter(){
>
> PreparedStatement preparedStatement =
> connection.prepareStatement("insert into msgpersecond ( time ,
> count , sendercompid , targetcompid ) values ( ? , ? , ? , ? )");
>
> connection.setAutoCommit( false ); // turn off auto-Commit
> }
>
> public void process(Object input){
>
> preparedStatement.setFloat( 2 , event.msgPerSecond );
> preparedStatement.addBatch( );
> writeCount++:
>
> if (writeCount > 50) {
> updateCounts = preparedStatement.executeBatch( );
> connection.commit( );
>
> preparedStatement.clearBatch( );
> writeCount=0;
> }
>
> }
> }
>
> process() gets called a lot. The code usually works fine, but we don't
> have a gap of 3 to 20 or so records that definitely are added to the
> batch but don't get written.
>
> I'd greatly appreciate any suggestions.
>
> Thanks
>

Are you checking the values in updateCounts? There might be a reason
your statements aren't being completed (the JDBC spec allows a driver to
continue the batch on errors, you check the return values of the
returned update counts to determine what went wrong).

Alternatively, you can add "continueBatchOnError=false" to your JDBC
URL, and you should get a BatchUpdateException if a single statement fails.

Since you're using transactions, you might be "missing" records from one
connection that are actually in the database due to the default
isolation level or REPEATABLE_READ as well (caling commit on the "other"
connection will cause it to use a snapshot that is more current and can
"see" the committed records from the connection doing the batch inserting).

-Mark
.



Relevant Pages

  • RE: BUG: JDBC connection disconnected, cant reconnect
    ... we've replaced the MS JDBC driver with jTDS JDBC driver, ... There is really nothing the driver can do that will take down SQL Server. ... Our problem is that the JDBC connection running on the localhost ... and then we can't reconnect to the database ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Using Java EE Connection Pools
    ... database with JDBC. ... Problem is, as this bean does work and calls out, opening and closing ... connections via straight JDBC is slow. ... The obvious solution is to use connection pooling; ...
    (comp.lang.java.databases)
  • Testing a JDBC connection
    ... Running an app that uses jdbc to connect to my sql 2005 database. ... Error initializing BEA ALI Studio ... I tested the connection useing a MS Datalink object, ...
    (comp.lang.java.databases)
  • RE: BUG: JDBC connection disconnected, cant reconnect
    ... Are you seeing the same symptoms (connect fine, lose connectivity, have to restart SQL Server to recover)? ... Subject: BUG: JDBC connection disconnected, ... Our problem is that the JDBC connection running on the localhost ... and then we can't reconnect to the database ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: Mixing P/R philosophy with OO (within J2EE).
    ... I have observed the work of literally hundreds of Java developers. ... Treating a database like a mere "persistence storage mechanisms" is on ... JDBC - Never before in history were so many database API's ... Topmind, if you're reading this, isn't this a good example of OOP? ...
    (comp.object)