1 19 20 package org.polepos.teams.jdbc.drivers.melbourne; 21 22 import java.sql.PreparedStatement ; 23 import java.sql.SQLException ; 24 25 import org.polepos.data.*; 26 import org.polepos.teams.jdbc.*; 27 28 35 public class BulkWritePreparedStatement implements BulkWriteStrategy 36 { 37 private final PreparedStatement mStmt; 38 39 42 public BulkWritePreparedStatement( JdbcCar car, String tablename ) 43 { 44 mStmt = car.prepareStatement( "insert into " + tablename + " (id,Name,FirstName,Points,LicenseID) values (?,?,?,?,?)" ); 45 } 46 47 50 public void savePilots(String tablename, Pilot[] p, int count, int index ) 51 { 52 try 53 { 54 for ( int i = 0; i < count; i++ ) 55 { 56 savePilot(p[i], index++ ); 57 } 58 59 if ( count > 0 ) 61 { 62 mStmt.executeBatch(); 63 } 64 } 65 catch ( SQLException sqlex ) 66 { 67 sqlex.printStackTrace(); 68 } 69 } 70 71 72 76 private void savePilot( Pilot p, int index ) throws SQLException 77 { 78 mStmt.setInt( 1, index ); 79 mStmt.setString( 2, p.getName() ); 80 mStmt.setString( 3, p.getFirstName() ); 81 mStmt.setInt( 4, p.getPoints() ); 82 mStmt.setInt( 5, p.getPoints() ); 83 mStmt.addBatch(); 84 } 85 } 86 | Popular Tags |