Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java mysql database access program in jsp  RSS feed

 
Greenhorn
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){} %>
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
 
Bartender
Posts: 19362
86
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.
 
Marshal
Posts: 58830
179
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!