JSP执行选择查询不显示结果

时间:2015-07-07 18:37:48

标签: mysql jsp

我找不到结果不会打印的原因。

需要专家的帮助。即使getString中的数据类型为int,也可以使用mysql

<%@page import="java.util.ArrayList"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%

try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException ex) {
        //out.println("DRIVER NOT FOUND");
    }

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet2 = null;
    try {
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/eenrol", "root", "");
        statement = connection.createStatement();
        resultSet2 = statement.executeQuery("SELECT IDNumber FROM student where status='pending'");
    } catch (Exception sql) {
        response.sendRedirect("studProfilePage.jsp");
    }
    try {
            ArrayList studList = new ArrayList();
            int rs = 0;
            while(resultSet2.next()){
                rs = resultSet2.getInt("IDNumber");
                    studList.add(rs);
                    request.setAttribute("pend", rs);
                    request.getRequestDispatcher("studProfilePage.jsp").forward(request, response);
            }
    } catch (Exception e){
        e.printStackTrace();
    }
%>

1 个答案:

答案 0 :(得分:0)

  1. 首先,你不应该在JSP中编写sql查询,它应该在DAO层,所以尽量避免将来使用。
  2. 我在代码中看不到print语句,这可能是问题所在。无论如何,如果你 想要在JSP中打印然后使用out.println(谢谢希望它有所帮助。