import java.net.URISyntaxException;
import java.sql.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;

import com.heroku.sdk.jdbc.DatabaseUrl;

class IdealPrice 
{
	private Connection connection = null;
	private Statement stmt = null;
	private ArrayList<NPD> listNPD;
	private Account account;
	private ArrayList<FG> listFG;
	
	public IdealPrice(ArrayList<NPD> newNPD)
	{
		ConnectDB();		
		listNPD = newNPD;
		
		LoadData();
	}
	
	public IdealPrice(Account newAcc)
	{
		ConnectDB();		
		account = newAcc;
		listNPD = new ArrayList<NPD>();
		listFG = new ArrayList<FG>();
		
		try {
			ResultSet rs = stmt.executeQuery("SELECT * FROM salesforce.NPD__c where Account_Name__c='" + newAcc.Id + "'");
			
	        while (rs.next()) 	
	        {
	        	listNPD.add(new NPD(rs));
	        }
	        
	        LoadData();
		} 
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	private void ConnectDB()
	{
		try {
			connection = DatabaseUrl.extract().getConnection();
			stmt = connection.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void LoadData()
	{
		String listID = "";
		//listID = "'a0fO000000AlPnSIAV', 'a0fO000000AlBIQIA3'";
		
		for(NPD npd : listNPD)
		{
			listID += "'" + npd.Id + "', ";
		}
		
		try 
		{
			ResultSet rs = stmt.executeQuery("SELECT * FROM salesforce.Sourcing__c where NPD__c in (" + listID + ")");
			while (rs.next()) 
	        {
	        	listFG.add(new FG(rs));
	        }
		} 
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getResult()
	{
		String output = "";
		
		for(FG fg : listFG)
		{
			output += fg.Name + "(" + fg.AnnualVolume + "), ";
		}
		return output;
		
		//return "Success";
	}
}

@@ -349,16 +349,46 @@
 stFG;%0A%09%0A
+%09private Integer count = 0;%0A%09%0A
 %09public 
@@ -1500,16 +1500,30 @@
 ry %0A%09%09%7B%0A
+%09%09%09count = 0;%0A
 %09%09%09Resul
@@ -1624,16 +1624,16 @@
 + %22)%22);%0A
-
 %09%09%09while
@@ -1687,24 +1687,43 @@
 ew FG(rs));%0A
+%09        %09count++;%0A
 %09        %7D%0A%09
@@ -1853,24 +1853,24 @@
 Result()%0A%09%7B%0A
-
 %09%09String out
@@ -1872,24 +1872,50 @@
 g output = %22
+Count: %22 + count + %22%3Cbr/%3E 
 %22;%0A%09%09%0A%09%09for(

Test Query WHERE IN v0.3