コード例 #1
0
 public JSONArray GetRestaurantsNearLoation(double lat, double lon) {
   try {
     if (conn == null) {
       return null;
     }
     Statement stmt = conn.createStatement();
     String sql =
         "SELECT business_id, name, full_address, categories, stars, latitude, longitude, city, state from RESTAURANTS LIMIT 10";
     // execute query expect result set
     ResultSet rs = stmt.executeQuery(sql);
     List<JSONObject> list = new ArrayList<JSONObject>();
     while (rs.next()) {
       JSONObject obj = new JSONObject();
       obj.append("business_id", rs.getString("business_id"));
       obj.append("name", rs.getString("name"));
       obj.append("stars", rs.getFloat("stars"));
       obj.append("latitude", rs.getFloat("latitude"));
       obj.append("longitude", rs.getFloat("longitude"));
       obj.append("full_address", rs.getString("full_address"));
       obj.append("city", rs.getString("city"));
       obj.append("state", rs.getString("state"));
       obj.append("categories", DBImport.stringToJSONArray(rs.getString("categories")));
       list.add(obj);
     }
     return new JSONArray(list);
   } catch (Exception e) {
     /* report an error */
     System.out.println(e.getMessage());
   }
   return null;
 }
コード例 #2
0
 private JSONObject getRestaurantsById(String businessId) {
   try {
     Statement stmt = conn.createStatement();
     String sql =
         "SELECT business_id, name, full_address, categories, stars, latitude, longitude, city, state, image_url from "
             + "RESTAURANTS where business_id='"
             + businessId
             + "'"
             + " ORDER BY stars DESC";
     ResultSet rs = stmt.executeQuery(sql);
     if (rs.next()) {
       JSONObject obj = new JSONObject();
       obj.append("business_id", rs.getString("business_id"));
       obj.append("name", rs.getString("name"));
       obj.append("stars", rs.getFloat("stars"));
       obj.append("latitude", rs.getFloat("latitude"));
       obj.append("longitude", rs.getFloat("longitude"));
       obj.append("full_address", rs.getString("full_address"));
       obj.append("city", rs.getString("city"));
       obj.append("state", rs.getString("state"));
       obj.append("categories", DBImport.stringToJSONArray(rs.getString("categories")));
       obj.append("image_url", rs.getString("image_url"));
       return obj;
     }
   } catch (Exception e) {
     /* report an error */
     System.out.println(e.getMessage());
   }
   return null;
 }