private String searchAndReturnDatainJSONFormat(String zipCodeArray[], String stateCode) {
   String query = "";
   String retValue = "[";
   PersistenceManager pm = PMF.get().getPersistenceManager();
   for (String zipCode : zipCodeArray) {
     if (zipCode != null && zipCode.length() > 0) {
       query =
           "select from "
               + EPAToxicDataBean.class.getName()
               + " where LocationZIPCode =='"
               + zipCode
               + "'";
     }
     // Adding this here to keep the compiler happy
     @SuppressWarnings("unchecked")
     List<EPAToxicDataBean> xmlDataList = (List<EPAToxicDataBean>) pm.newQuery(query).execute();
     int beanCounter = 1;
     if (xmlDataList != null) {
       for (EPAToxicDataBean rec : xmlDataList) {
         org.json.JSONObject jsonObject = new org.json.JSONObject(rec);
         retValue += jsonObject.toString();
         if (xmlDataList.size() > 1 && beanCounter != xmlDataList.size()) {
           retValue += ",";
         }
         ++beanCounter;
       }
     }
     retValue += "]";
   }
   return retValue;
 }
  @SuppressWarnings("unchecked")
  private String searchAndReturnDatainJSONFormat(
      String zipCode, String statCode, String[] latlong) {
    String query = "";
    String retValue = "[";
    PersistenceManager pm = PMF.get().getPersistenceManager();
    if (zipCode != null && zipCode.length() > 0) {
      query =
          "SELECT FROM  com.mycompany.sampleProject.server.EPAToxicDataBean "
              + "where LocationZIPCode.startsWith(tradeName) "
              + "parameters String tradeName";

      /*
       * query = "select from " + EPAToxicDataBean.class.getName() +
       * " where LocationZIPCode.startsWith('" + zipCode + "')";
       */
    }
    if (statCode != null && statCode.length() > 0) {
      query =
          "select from "
              + EPAToxicDataBean.class.getName()
              + " where LocationAddressStateCode =='"
              + statCode
              + "'";
    }
    // Adding this here to keep the compiler happy
    @SuppressWarnings("cast")
    List<EPAToxicDataBean> xmlDataList =
        (List<EPAToxicDataBean>) pm.newQuery(query).execute(zipCode);
    int beanCounter = 1;
    if (xmlDataList != null) {
      for (EPAToxicDataBean rec : xmlDataList) {
        org.json.JSONObject jsonObject = new org.json.JSONObject(rec);
        retValue += jsonObject.toString();
        if (xmlDataList.size() > 1 && beanCounter != xmlDataList.size()) {
          retValue += ",";
        }
        ++beanCounter;
      }
      retValue += "]";
    }
    return retValue;
  }
  @SuppressWarnings("unchecked")
  private String searchAndReturnDatainJSONFormatForWebApp(
      String sLong, String sLat, String radius, String result) {
    String query = "";
    String retValue = "";
    PersistenceManager pm = PMF.get().getPersistenceManager();

    StringBuffer sb = new StringBuffer(100);
    sb.append("http://ws.geonames.net/findNearbyPostalCodesJSON?lat=");
    sb.append(sLat);
    sb.append("&lng=");
    sb.append(sLong);
    sb.append("&radius=");
    sb.append(radius);
    sb.append("&maxRows=100");
    sb.append("&username="******"URL:" + sb);
    String JSONResult = callServletToGetData(url);
    String zipCodeArray[] = null;

    Integer iResult = new Integer(result);

    String state = parseJSONDatatoGetState(JSONResult);
    zipCodeArray = parseJSONData(JSONResult);
    ArrayList beanList = new ArrayList();
    List<EPAToxicDataBean> xmlDataList = null;

    try {
      if (zipCodeArray != null) {
        int resultCounter = 0;
        System.out.println("Startime" + new Date());
        HashMap containsMap = new HashMap();
        for (String zipCode : zipCodeArray) {

          if (resultCounter >= iResult) {
            break;
          }
          query =
              "SELECT FROM  com.mycompany.sampleProject.server.EPAToxicDataBean "
                  + "where LocationZIPCode.startsWith(tradeName) "
                  + "parameters String tradeName";
          System.out.println("Executing Query:" + query);
          xmlDataList = (List<EPAToxicDataBean>) pm.newQuery(query).execute(zipCode);

          if (xmlDataList != null) {

            for (EPAToxicDataBean rec : xmlDataList) {
              if (resultCounter < iResult) {
                if (!containsMap.containsKey(rec.getFacilityregistryId())) {
                  beanList.add(rec);
                  ++resultCounter;
                  containsMap.put(rec.getFacilityregistryId(), 0);
                  System.out.println("ResultSize time:" + beanList.size());
                } else {
                  continue;
                }

              } else {
                break;
              }
            }
          }
        }
      }
      if (beanList.size() > 0) {

        StringBuffer retValuBuffer = new StringBuffer(8000);
        retValuBuffer.append("[");
        int beanCounter = 0;
        for (int i = 0; i < beanList.size(); ++i) {
          org.json.JSONObject jsonObject = new org.json.JSONObject(beanList.get(i));
          retValuBuffer.append(jsonObject.toString());
          if ((beanCounter != beanList.size() - 1) && beanList.size() > 1) {
            retValuBuffer.append(",");
          }
          ++beanCounter;
        }
        retValuBuffer.append("]");

        retValue = retValuBuffer.toString();
      }
    } catch (Exception exec) {
      System.out.println("Error" + exec.getMessage());
      System.out.println("Error at time" + new Date());
    } finally {
      StringBuffer retValuBuffer = new StringBuffer(8000);
      retValuBuffer.append("[");
      int beanCounter = 0;
      for (int i = 0; i < beanList.size(); ++i) {
        org.json.JSONObject jsonObject = new org.json.JSONObject(beanList.get(i));
        retValuBuffer.append(jsonObject.toString());
        if ((beanCounter != beanList.size() - 1) && beanList.size() > 1) {
          retValuBuffer.append(",");
        }
        ++beanCounter;
      }
      retValuBuffer.append("]");
      JsonReturnValueForIphone = retValuBuffer.toString();
    }
    return retValue;
  }