Apache Tomcat WebService中的服务错误

时间:2014-11-03 13:38:25

标签: java sql json web-services tomcat

在Web服务中添加此方法后,我在apache tomcat Web服务中收到错误的服务:

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();
}

对于此方法,我将从数据库检索的数据传递给JSON。添加后,当我在服务器上运行Web服务时,收到此错误消息:

Faculty Services:
C:\Users\Desktop\Eclipse EE\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SplashWebService\WEB-INF\services\SplashWebService

删除此方法后,Web服务再次完美运行。有任何想法吗?

提前致谢。

0 个答案:

没有答案