MySQL查询返回空结果集

时间:2014-11-18 19:20:46

标签: java mysql jdbc resultset

目前我正在编写一个非常简单的Java Servlet,它只执行一个查询并打印结果。

我面临的问题是它使用JBoss作为AS在本地工作。当我将它远程部署到TomCat时,相同的查询没有返回任何结果。

我的观察:

  • 该表有数据。我使用SQuirrelSQL检查(大约100行);
  • 使用mysql cli也没有返回任何结果;
  • 以下代码返回"是是是是..."本地,但只是远程"去"

代码:

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setHeader("Content-Type", "application/json");
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace(res.getWriter());
    }

    List<Opportunity> opportunityList = new ArrayList<Opportunity>();

    Connection conn = null;
    Statement st = null;
    ResultSet rs = null;
    try {
        conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname", "dbuser", "dbpwd");
        st = conn.createStatement();
        rs = st.executeQuery(QUERY);
        while(rs.next()) {
            res.getWriter().print("yes ");
            opportunityList.add(new Opportunity(rs));
        }
    } catch (SQLException e) {
        opportunityList.clear();
        res.getWriter().print("nooo ");
        res.getWriter().println(e.toString());
    } finally {
        try {
            res.getWriter().write("go ");
            conn.close();
            st.close();
            rs.close();
        } catch (Exception e) {
            res.getWriter().write("noooo2");
            res.getWriter().println(e.toString());
        }
    }

    res.getWriter().write(new Gson().toJson(opportunityList));

}

编辑 - 查询:

SELECT o.ID, o.NAME, s.DESCRIPTION, pt.NAME, o.START_DATE, so.OWNER, 
FROM SCOUT_OPPORTUNITY so 
INNER JOIN OPPORTUNITY o ON so.OPPORTUNITY_ID = o.ID 
INNER JOIN STATUS_DESC s ON s.NAME = o.STATUS_NAME 
LEFT JOIN PROJECT_TYPE pt ON pt.ID = o.PROJECT_TYPE_ID 
ORDER BY o.ID

0 个答案:

没有答案