• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

showing resultset

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply
I guess this was the solution
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic