Re: batch update is sporadically incomplete
- From: Mark Matthews <mark@xxxxxxxxx>
- Date: Mon, 05 Dec 2005 09:51:33 -0600
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
.
- References:
- batch update is sporadically incomplete
- From: Daisy
- batch update is sporadically incomplete
- Prev by Date: Re: Hidden (not visible, but usable) fields in jdbTable
- Next by Date: Re: batch update is sporadically incomplete
- Previous by thread: batch update is sporadically incomplete
- Next by thread: Re: batch update is sporadically incomplete
- Index(es):
Relevant Pages
|
|