This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Java mysql database access program in jsp  RSS feed

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.

Posts: 20092
Android Eclipse IDE 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: 62144
  • 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.
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!