JSP页面不显示输出

时间:2015-01-13 16:17:36

标签: jsp ms-access database-connection

我想在访问数据库的表中显示ID。我的代码运行没有任何错误。

但代码不显示任何内容。只有Html页面中的白色屏幕。

这是我的代码:

<%@page import="java.sql.*" %>
<html>
<body>

<%
    try
    {
        Connection con = null;
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con=DriverManager.getConnection("jdbc:odbc:AccessDatabase", "", "");
        Statement stmt = con.createStatement();
        String str= "SELECT * FROM emp_table";
        ResultSet rs = stmt.executeQuery(str);

    while(rs.next())
    {
%>
        <%= rs.getInt("ID") %>
<%
    }

    rs.close();
    stmt.close();
    con.close();
}
    catch(Exception e) 
    {
        System.out.println(e);
    }

%>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

似乎你在 emp_table 中只有一条记录,当你首先调用rs.next时它正在访问迭代器obj(ResultSet),但你没有正确使用它。

试试这个,

 while(rs.hasnext())
        {
    %>    yourDatabaseObj = rs.next(); 

            <%= yourDatabaseObj.getInt("ID") %>
    <%
        }
相关问题