• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

showing resultset

 
Preeti Sikri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys how we show single resultset on the JSP page I have a bean in which I have get/set method and I'm connecting to database my query is
select name , phone from book where id = 9
now I'll only get one recordset so how can I show that recordset pls help me out ..
Any sample code will be great
Thanks for any Help
Regards Preeti
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about in your JSP page? If so, just get the ResultSet from your query:
<%
Connection conn = <set up connection stuff...>
String name=null, phone=null;
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select name, phone from book where ID = 9");
while (rs.next() ) {
name = rs.getString(1);
phone = rs.getString(2);
}
%>
..
Name = <%=name%>
Phone = <%=phone%>
HTH
Brian
 
Preeti Sikri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply
I guess this was the solution
 
Geoff Tate
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also wrap the while loop in an HTML table like so:
<table>
<% while(rs.next()) { %>
<tr>
<td> <%= rs.getString("name"); %> </td>
<td> <%= rs.getString("phone"); %> </td>
</tr>
<% } %>
</table>
note the use of the <%. This kinda breaks the rules of the MVC paradigm, but I have seen so many times now.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic