Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting JDBC output

 
srini kami
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am having trouble formatting output from database to browser.
I have follwoing code in try block of servlet.
try{

Statement stmt = conn.createStatement();
String req_show= "select title from request";

ResultSet rs = stmt.executeQuery(req_show);

while (rs.next() ) {

String titl = rs.getString(1)+"\n";
out.println(titl);out.println("\n");
I get values from above column (title)but they are showing in one row like following
//output
test test check
I want it to show as a cloumn
test
test
check
how do i do that?. I will appreciate it it if you could help me with this.
Thank you
 
Bill Kemp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised that the code you are showing doesn't work, but you could try using "<p>" tag or a "<br>" tag in the output to put a new paragraph or break, respectively.
Bill
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out.println(titl); out.println("\n");
This would cause the titl string to be followed by a new line character. So, if you were to view the source of the output html document, the different titls would be displayed on different lines. A web browser interprets new line characters about the same as any other whitespace (such as spaces and tabs), so it just displays a single space.
Use out.println("<br>"); or out.println("<p>"); as Bill suggested. The browser will display a new line with either of these tags. (The paragraph tag will probably be displayed with an additional blank line.)
 
srini kami
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you guys. I tried <p> and <br>. It worked fine.
Thanx again i apprecaite it.
Srini
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic