user1700794
user1700794

Reputation:

Result Set not displaying data in JSP

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.

Upvotes: 1

Views: 544

Answers (2)

Makky
Makky

Reputation: 17461

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.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240928

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

Upvotes: 3

Related Questions