public synchronized int delete ( Connection conn , T obj ) 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 < primaryKeys . length ; i ++ ) { fields [ primaryKeyIndices [ i ] ] . bindVariable ( deleteStmt , obj , i + 1 ) ; } nDeleted = deleteStmt . executeUpdate ( ) ; deleteStmt . close ( ) ; return nDeleted ; }
Delete record with specified value of primary key from the table .