public synchronized int delete ( Connection conn , T [ ] objects ) throws SQLException { if ( primaryKeys == null ) { throw new IllegalStateException ( "No primary key for table " + name + "." ) ; } int nDeleted = 0 ; StringBuilder sql = new StringBuilder ( "delete from " + name + " where " + primaryKeys [ 0 ] + " = ?" ) ; for ( int i = 1 ; i < primaryKeys . length ; i ++ ) { sql . append ( " and " ) . append ( primaryKeys [ i ] ) . append ( " = ?" ) ; } PreparedStatement deleteStmt = conn . prepareStatement ( sql . toString ( ) ) ; for ( int i = 0 ; i < objects . length ; i ++ ) { for ( int j = 0 ; j < primaryKeys . length ; j ++ ) { fields [ primaryKeyIndices [ j ] ] . bindVariable ( deleteStmt , objects [ i ] , j + 1 ) ; } deleteStmt . addBatch ( ) ; } int rc [ ] = deleteStmt . executeBatch ( ) ; for ( int k = 0 ; k < rc . length ; k ++ ) { nDeleted += rc [ k ] ; } deleteStmt . close ( ) ; return nDeleted ; }
Delete records with specified primary keys from the table .