In servlet I am trying to put a list in json object, but i cant able to find what is the error. I am calling servlet from ajax call, Here is servlet code,
Latlng latlng=new Latlng();
List<Latlng> vehicleList = new ArrayList<Latlng>();
sql ="SELECT a.vehicleno,a.lat,a.lng,a.status,a.rdate,a.rtime from latlng a,vehicle_details b where a.vehicleno=b.vehicleno and b.clientid="+clientid +" and b.groupid in(select groupid from group_details where groupname='"+gname+"' and clientid='"+clientid+"')";
resultSet = statement.executeQuery(sql);
while(resultSet.next()){
String s=resultSet.getString("vehicleno");
latlng.setVehicleno(resultSet.getString("vehicleno"));
latlng.setLat(resultSet.getString("lat"));
latlng.setLat(resultSet.getString("lng"));
latlng.setLat(resultSet.getString("status"));
latlng.setLat(resultSet.getString("rdate"));
latlng.setLat(resultSet.getString("rtime"));
vehicleList.add(latlng);
System.out.println(vehicleList);
String json = new Gson().toJson(vehicleList);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
is there anything wrong in it. It is not even displaying exception also.
ClassNotFoundExceptions orSQLExceptions that occur (writing the exceptions to the console which isn't any help for servlet code). Also, you should probably put the last four lines in yourwhile-loopjust after it instead.e.printStackTrace()and then inspect theevariable.