0
String getCity = request.getParameter("name1");
HttpSession session = request.getSession();
try {
    ConnectToDb db = new ConnectToDb();

    con =db.getConnect();
    pstmt = con.prepareStatement("select Name, CountryCode, District, Population from city where name =?");
    pstmt.setString(1, getCity);
    rs=pstmt.executeQuery();
    ArrayList<getCity> getinfo = new ArrayList<getCity>();

    while(rs.next()){
        getCity gc = new getCity();
        gc.setCity(rs.getString("name"));
        gc.setContryCode(rs.getString("CountryCode"));
        gc.setDistrict(rs.getString("district"));
        gc.setPopulation(rs.getString("population"));
        getinfo.add(gc);
    }

    JSONObject jobj = new JSONObject();
    jobj.put("city", getinfo);
    System.out.println(jobj);

} catch (Exception e) {
    System.out.println(e.getMessage());
}

output :

{"city":[{"city":"Perm","district":"Perm","contryCode":"RUS","population":"1009700"}]}

But same code when I execute in other machine output gets something like this: {"city":[{"com.getCity.@AF345E"}]}.

Why does this is happen?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

2
com.getCity.@AF345E

It is an "getCity" object without implementing "toString" method. Check your code.

Tommy
  • 3,044
  • 1
  • 14
  • 13