addBatch() inserts
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Faye_Spath
Posted On:   Thursday, March 11, 2004 07:47 AM

I am trying to do an add batch and only getting the very last record updated to the database. I am reading a Comma delimited file and calling the addBatch method after setting up the prepared statement. Once I read 10 records I execute the batch through the executeBatch method. When I go and check the database I only have the last record. Was wondering if anyone has run in to this problem and how they solved it. This is a snippet of my code.... .... prepStat.setFloat(51, field51 ); System.out.println("addBatch"); prepStat.addBatch(); batchCount = batchCount + 1; System.out.println("batchCount " + batchCount); if (batchCount == 10) {    More>>

I am trying to do an add batch and only getting the very last record updated to the database.


I am reading a Comma delimited file and calling the addBatch method after setting up the prepared statement. Once I read 10 records I execute the batch through the executeBatch method. When I go and check the database I only have the last record. Was wondering if anyone has run in to this problem and how they solved it.

This is a snippet of my code....

....
prepStat.setFloat(51, field51 );

System.out.println("addBatch");
prepStat.addBatch();

batchCount = batchCount + 1;
System.out.println("batchCount " + batchCount);
if (batchCount == 10) {
try{
System.out.println("Executing Batch");
//int updateCount = Integer.parseInt( prepStat.executeBatch().toString());
prepStat.executeBatch();
System.out.println("updateCount");
conn.commit();
conn.setAutoCommit(true);
// prepStat.clearBatch();
batchCount = 0;
prepStat.close();
}

catch(BatchUpdateException b) {
System.err.println(
"----BatchUpdateException----");
System.err.println(
"SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
System.err.println(
"Vendor: " + b.getErrorCode());
System.err.print("Update counts: ");
int [] updateCounts = b.getUpdateCounts();
for (int i = 0;
i < updateCounts.length; i++) {
System.err.print(updateCounts[i] + " ");
}
}

   <<Less
About | Sitemap | Contact