hello all, I am new to java and am trying to do a simple thing.
I can connect to a database and display the first row in a jsp page, but I need to display all rows.
so far I have this .
// Create a Statement Object
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(queryString);
int numCols = rs.getMetaData().getColumnCount();
while (rs.next()) {
for (int i=1; i<=numCols; i++)
{
String RS_Name = rs.getString("name"
;
String RS_Postcode = rs.getString("Postcode"
;
String RS_County = rs.getString("County"
;
ServletContext context = getServletContext();
req.setAttribute("RS_Name", RS_Name);
req.setAttribute("RS_Postcode", RS_Postcode);
req.setAttribute("RS_County", RS_County);
context.getRequestDispatcher("Result.jsp"
.forward(req, resp);
}
and my jsp page has the following :
<%
String name = (String) request.getAttribute("RS_Name"
;
String postcode = (String) request.getAttribute("RS_Postcode"
;
String county = (String) request.getAttribute("RS_County"
;
out.println(name + " " + postcode + " " + county);
%>
how can I display all data ? do I need to create the data as a vector or something ?
thank you very much for your help.
I can connect to a database and display the first row in a jsp page, but I need to display all rows.
so far I have this .
// Create a Statement Object
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(queryString);
int numCols = rs.getMetaData().getColumnCount();
while (rs.next()) {
for (int i=1; i<=numCols; i++)
{
String RS_Name = rs.getString("name"
String RS_Postcode = rs.getString("Postcode"
String RS_County = rs.getString("County"
ServletContext context = getServletContext();
req.setAttribute("RS_Name", RS_Name);
req.setAttribute("RS_Postcode", RS_Postcode);
req.setAttribute("RS_County", RS_County);
context.getRequestDispatcher("Result.jsp"
}
and my jsp page has the following :
<%
String name = (String) request.getAttribute("RS_Name"
String postcode = (String) request.getAttribute("RS_Postcode"
String county = (String) request.getAttribute("RS_County"
out.println(name + " " + postcode + " " + county);
%>
how can I display all data ? do I need to create the data as a vector or something ?
thank you very much for your help.