如何在jsp页面显示数据库查询的记录
小弟手动编写了一个action来实现数据库连接,在数据库查询中产生的结果集不知如何显示在jsp页面上
<%!String url = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;%>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://localhost/stockquery?user=root&password=123456";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from stock where id="+id);
while (rs.next()) {
%>
<%=rs.getString("id")%>
<%=rs.getString("name")%><br>
<%
}
} catch (Exception e) {
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
%>