File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "showing resultset" Watch "showing resultset" New topic

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 ( ) {
name = rs.getString(1);
phone = rs.getString(2);
Name = <%=name%>
Phone = <%=phone%>
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:
<% while( { %>
<td> <%= rs.getString("name"); %> </td>
<td> <%= rs.getString("phone"); %> </td>
<% } %>
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>
I agree. Here's the link:
subject: showing resultset
It's not a secret anymore!