• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java mysql database access program in jsp

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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){} %>
myuserwebpagesummarydatumcomments
<%=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.

Soumitra
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic