Problem Definition:
I have a Database table with huge amount of data(more than 100,000 rows) , table structure is like
AppID DocID DocSta
Every time you have a data-centric problem (as opposed to a Java domain-model-centric one), you should use SQL directly. Your database will be much faster than your Java code, because calculations can be performed closely to the data, instead of transferring all of it through the wire and into your memory. See also "2. Processing Data in Memory" of this blog post.
You can achieve this with JDBC directly, or with a native query, or with any third-party SQL library of your choice, such as MyBatis or jOOQ.
Your problem can be trivially solved with any of these queries:
SELECT [AppID], [DocStatus], count(*)
FROM [MyTable]
GROUP BY [AppID], [DocStatus]
Example on SQLFiddle
SELECT [AppID],
(SELECT count(*) FROM [MyTable] [t2]
WHERE [t1].[AppID] = [t2].[AppID]
AND [DocStatus] = 0) [Status_0],
(SELECT count(*) FROM [MyTable] [t2]
WHERE [t1].[AppID] = [t2].[AppID]
AND [DocStatus] = 1) [Status_1]
FROM [MyTable] [t1]
GROUP BY [AppID]
Example on SQLFiddle
SELECT [AppID],
SUM(IIF([DocStatus] = 0, 1, 0)) [Status_0],
SUM(IIF([DocStatus] = 1, 1, 0)) [Status_1]
FROM [MyTable] [t1]
GROUP BY [AppID]
Example on SQLFiddle
SELECT [AppID], [0], [1]
FROM (
SELECT [AppID], [DocStatus]
FROM [MyTable]
) [t]
PIVOT (count([DocStatus]) FOR [DocStatus] IN ([0], [1])) [pvt]
Example on SQLFiddle