aspose file tools*
The moose likes Servlets and the fly likes Working on the problem since days, pl help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Working on the problem since days, pl help!" Watch "Working on the problem since days, pl help!" New topic
Author

Working on the problem since days, pl help!

Othmar Stehlik
Ranch Hand

Joined: Jul 24, 2001
Posts: 36
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

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Jul 24, 2001
Posts: 36
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

Joined: May 04, 2001
Posts: 19
HI Stehlik,
try this ...
while(rs.next()){
out.println(rs.getString("sname") );
out.println("<HR>");
}
hopefully it works.
Aamir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working on the problem since days, pl help!