Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working on the problem since days, pl help!

 
Othmar Stehlik
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I�m writting on a guestbook servlet, with database connection nad I have big problems with printing out the records.
A user can send his name and comment, this is stored in the database, then I want to Select the records, and every post should appear between 2 horizontal lines.
I tried with getArray() and a for loop, to select from the Result Set, here are Code Snippets!

try{
Connection c = DriverManager.getConnection(url);
Statement s = c.createStatement();
String sqlString = ("SELECT sname FROM actor");

ResultSet rs = s.executeQuery(sqlString);
Object anArray= rs.getArray(1);

response.setContentType("text/html");
PrintWriter out = response.getWriter();



// Write the content
out.println("<HTML>");
out.println("<BODY>");
out.println("<HR>");
for(int i=0; i<rs.next(); i++){
while(rs.next())
break;
out.println(rs.getString("sname") );

out.println("<HR>");

out.println("</BODY>");
out.println("</HTML>");
out.close();
}
and so on, please help, I hope I provided enough information, any suggestion is really appreciated!
Othmar
[This message has been edited by Othmar Stehlik (edited August 29, 2001).]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while(rs.next())
break;
Means that the first time rs.next() returns true, you jump out of the for loop! Why?
Bill
 
Othmar Stehlik
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I tried it with the for loop, after posting this message, but it is wrong:
for(int i=0; ; i++){
while(rs.next())
continue;
}
The for loop never ends, but I cant use for(int i=0; i<rs.next(); i++)
And the brek statement and the continue statement don�t work
I want to go through every row in the table and print every entry between 2 <HR>s.
With a simple loop and Continue only the first entry is printed, with break only the last.
I hope you have some suggestions.
Thnx in advance
Othmar
[This message has been edited by Othmar Stehlik (edited August 31, 2001).]
 
aamir abbas
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Stehlik,
try this ...
while(rs.next()){
out.println(rs.getString("sname") );
out.println("<HR>");
}
hopefully it works.
Aamir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic