This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes showing resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "showing resultset" Watch "showing resultset" New topic
Author

showing resultset

Preeti Sikri
Ranch Hand

Joined: Mar 01, 2001
Posts: 30
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

Joined: Nov 02, 2000
Posts: 195
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

Joined: Mar 01, 2001
Posts: 30
thanks for the reply
I guess this was the solution
Geoff Tate
Ranch Hand

Joined: Feb 06, 2001
Posts: 55
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.



<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR> fantastic, a towel? <HR></BLOCKQUOTE>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: showing resultset