• 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 ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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.next()){     %> <% } 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: 19732
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: 60163
  • 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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!