Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java mysql database access program in jsp

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@page import="java.sql.*"%>
<% try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/feedback?"                            + "user=sqluser&password=sqluserpw"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from feedback.comments"); while({    %> <% } rs.close(); st.close(); con.close(); } catch(Exception e){} %>
<%=rs.getString("myuser")%> <%=rs.getString("webpage")%> <%=rs.getString("summary")%> <%=rs.getString("datum")%> <%=rs.getString("comments")%>

in output only headings(myuser,webpage,summary,datum,comments are showing in html tabular form. but no data is shown. 1 row of data is there in table feedback.comments. Can anyone troubleshoot it? working in java after long time. Thanks in advance.

Saloon Keeper
Posts: 22248
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Soumitra!

1. Solve it? I can't even read it! The "Code" button on our message editor allows you to insert tags that will keep code and data/xml samples from getting scrambled like that.

2. Class.forName for database drivers has been obsolete for a very, very long time now.

3. You shouldn't be using the DriverManager in web code. Web servers support database connection pools. It's much more efficient for multi-user webapps.

4. You also shouldn't be coding logic on a JSP page. That also is a long-obsoleted practice. The JSP should be a template populated by a servlet. The servlet is where your database code should go.
Posts: 69752
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were asked two days ago to edit your post; if we can't decipher your caode, we can't help you, I am afraid.
We find this kind of rampant individuality very disturbing. But not this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic