Q:

How count Rows of CSV file Efficiently in Java

I have developed a code which opens a CSV file and counts the number of rows using a for loop, but I feel this method is not efficient and causes several delays.

TargetFile.mdb has 120 rows
report.csv has 11000 rows

If I use this method the code needs to run 120*11000=1320000 times to count each resource count. Here is my code:
Here is new and working code which count rows efficiently by Xavier Delamotte:
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import au.com.bytecode.opencsv.CSVReader;

import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.Table;

public class newcount {

    public static class ValueKey{
        String mdmId;
        String pgName;

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((mdmId == null) ? 0 : mdmId.hashCode());
            result = prime * result
                + ((pgName == null) ? 0 : pgName.hashCode());
            return result;
        }
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            ValueKey other = (ValueKey) obj;
            if (mdmId == null) {
                if (other.mdmId != null)
                    return false;
            } else if (!mdmId.equals(other.mdmId))
                return false;
            if (pgName == null) {
                if (other.pgName != null)
                    return false;
            } else if (!pgName.equals(other.pgName))
                return false;
            return true;
        }
        public ValueKey(String mdmId, String pgName) {
            super();
            this.mdmId = mdmId;
            this.pgName = pgName;
        }
    }

    public static void main(String[] args) throws IOException, SQLException,Throwable{

        Integer count;

        String MDMID,NAME,PGNAME,PGTARGET,TEAM;

        Table RESOURCES = Database.open(new File("C:/STATS/TargetFile.mdb")).getTable("RESOURCES");
        int pcount = RESOURCES.getRowCount();

        String csvFilename = "C:\\MDMSTATS\\APEX\\report.csv";
        CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
        List<String[]> content = csvReader.readAll();
        Map<ValueKey, Integer> csvValuesCount = new HashMap<ValueKey, Integer>();
        for (String[] rowcsv  : content) {
            ValueKey key = new ValueKey(rowcsv[6], rowcsv[1]);
            count = csvValuesCount.get(key);
            csvValuesCount.put(key,count == null ? 1: count + 1);

        }

        //int count = 0;
        // Taking 1st resource data
        for (int i = 0; i < pcount-25; i++) {
            Map<String, Object> row = RESOURCES.getNextRow();
            TEAM = row.get("TEAM").toString();
            MDMID = row.get("MDM ID").toString();
            NAME = row.get("RESOURCE NAME").toString();
            PGNAME = row.get("PG NAME").toString();
            PGTARGET = row.get("PG TARGET").toString();
            int PGTARGETI = Integer.parseInt(PGTARGET);
            Integer countInteger = csvValuesCount.get(new ValueKey(MDMID, PGNAME));
            count = countInteger == null ? 0: countInteger;
            System.out.println(NAME+"\t"+PGNAME+"\t"+count);

        }
    }
}

A:

I would suggest to read the csv file only one time, and to count the occurence of the key composed by mdmId and pgName.
If you have guava, you could have used a MultiSet<ValueKey> http://guava-libraries.googlecode.com/svn-history/r8/trunk/javadoc/com/google/common/collect/Multiset.html instead  of the Map<ValueKey,Integer>
edit: and to use the ValueKey class you need to  put in another file or declare it static.
class ValueKey:
    public static class ValueKey{
        String mdmId;
        String pgName;
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((mdmId == null) ? 0 : mdmId.hashCode());
            result = prime * result
                    + ((pgName == null) ? 0 : pgName.hashCode());
            return result;
        }
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            ValueKey other = (ValueKey) obj;
            if (mdmId == null) {
                if (other.mdmId != null)
                    return false;
            } else if (!mdmId.equals(other.mdmId))
                return false;
            if (pgName == null) {
                if (other.pgName != null)
                    return false;
            } else if (!pgName.equals(other.pgName))
                return false;
            return true;
        }
        public ValueKey(String mdmId, String pgName) {
            super();
            this.mdmId = mdmId;
            this.pgName = pgName;
        }
    }

your method:
    Table RESOURCES = Database.open(new File("TargetFile.mdb")).getTable("RESOURCES");
    int pcount = RESOURCES.getRowCount();

    String csvFilename = "C:\\STATS\\APEX\\report.csv";
    CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
    List<String[]> content = csvReader.readAll();
    Map<ValueKey, Integer> csvValuesCount = new HashMap<ValueKey, Integer>();
    for (String[] rowcsv  : content) {
        ValueKey key = new ValueKey(rowcsv[6], rowcsv[1]);
        Integer count = csvValuesCount.get(key);
        csvValuesCount.put(key,count == null ? 1: count + 1);

    }

    int count = 0;
    // Taking 1st resource data
    for (int i = 0; i < pcount; i++) {
        Map<String, Object> row = RESOURCES.getNextRow();
        TEAM = row.get("TEAM").toString();
        MDMID = row.get("MDM ID").toString();
        NAME = row.get("RESOURCE NAME").toString();
        PGNAME = row.get("PG NAME").toString();
        PGTARGET = row.get("PG TARGET").toString();
        int PGTARGETI = Integer.parseInt(PGTARGET);
        Integer countInteger = csvValuesCount.get(new ValueKey(MDMID, PGNAME));
        count = countInteger == null ? 0: countInteger;
    }

