• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

formatting JDBC output

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you guys. I tried <p> and <br>. It worked fine.
Thanx again i apprecaite it.
Srini
 
reply
    Bookmark Topic Watch Topic
  • New Topic