问题
I am getting faulty services in my apache tomcat web service after adding this method in the web service:
public String getAllEvent() {
JSONArray jsonArray = new JSONArray();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/mydb", "root", "root");
PreparedStatement statement = con
.prepareStatement("SELECT * FROM event");
ResultSet result = statement.executeQuery();
while (result.next()) {
JSONObject eventInfo = new JSONObject();
eventInfo.put("eventID", result.getString("eventID"));
eventInfo.put("eventName", result.getString("eventName"));
eventInfo.put("eventDesc", result.getString("eventDesc"));
eventInfo.put("eventDate", result.getString("eventDate"));
eventInfo.put("eventTime", result.getString("eventTime"));
eventInfo.put("eventX", result.getString("eventX"));
eventInfo.put("eventY", result.getString("eventY"));
eventInfo.put("eventBy", result.getString("eventBy"));
jsonArray.put(eventInfo);
}
String jsonStr = jsonArray.toString();
return jsonStr;
}
catch (JSONException je) {
return null;
} catch (Exception exc) {
System.out.println(exc.getMessage());
}
return jsonArray.toString();
}
For this method, I am passing the data retrieved from database into JSON. After I added it, when I run the web service on server, I am getting this error message:
Faculty Services:
C:\Users\Desktop\Eclipse EE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SplashWebService\WEB-INF\services\SplashWebService
The web service runs perfectly again after I removed this method. Any ideas?
Thanks in advance.
来源:https://stackoverflow.com/questions/26715533/faulty-service-in-apache-tomcat-webservice