1

I am retrieving data from database in JSP in a result set. ResultSet in not empty but it is not displaying data in html tags, i.e. h3 is empty

ResultSet rs = null;
String sqlStr;

sqlStr = "SELECT * from IDEAS";
Statement stmt = con.createStatement();
rs = stmt.executeQuery(sqlStr);

<% while (rs.next()) { %>
<h3> <% rs.getString("heading"); %></h3>
<% } %>

All other statements like insert , delete are working.

1
  • Ideally you shouldn't be doing that. JSP is definitely not a place to access Result Set. If you writing real code to be deployed somewhere in production, I will say this is a BIG BIG no. Read more about oops concept and segregate and modularize your code. Commented May 6, 2013 at 7:48

2 Answers 2

3

It should be

<h3> <%= rs.getString("heading"); %></h3>

Note: putting java code in view is discouraged, put it in Servlet or Controller and use JSTL in view layer in jsp

Sign up to request clarification or add additional context in comments.

1 Comment

I have used it , but for the question I wrote the code that way. Thanks for the help :)
0

Its a not a good practice to use that code in JSP layer . You should be using a backbean where you do your coding and just retrieve data to be viewed in JSP using JSTL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.