i want to load data from mysql to jsp but I have an unprocessable error


i want to load data from mysql to jsp but I have an unprocessable error


enter code here



this is java code to load data from database to jsp



package dao;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import model.Category;
import utils.DBConnect;

public class CategoryDAO {

public ArrayList<Category> getListCategory() throws SQLException {
Connection connect = DBConnect.getConnection();
ArrayList<Category> listCategory = new ArrayList<>();
String sql = "SELECT * FROM category";
PreparedStatement ps = connect.prepareCall(sql);
ResultSet rs = ps.executeQuery();

while (rs.next()) {
Category category = new Category();
category.setCategoryID(rs.getInt("CategoryID"));
category.setCategoryName(rs.getString("CategoryName"));
listCategory.add(category);
}

return listCategory;
};

}



this is html file to display data, i am load category


<ul class="drop">
<%
for (Category c : cateDao.getListCategory()) {
%>
<li><a href="product.jsp?category=<%=c.getCategoryID()%>"><%= c.getCategoryName() %></a></li>
<%
}
%>
</ul>



The error section will be posted in the comment




1 Answer
1



I am not sure about my answer, but...
Method connect.prepareCall calls stored procedures from database, so, may be you should use connect.prepareStatement instead.





i try but not successful!
– Tri Vu Duc
Jun 30 at 8:42





lỗi thông báo ở đoạn code này PreparedStatement ps = (PreparedStatement) connect.prepareStatement(sql);
– Tri Vu Duc
Jun 30 at 8:44






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Render GeoTiff to on browser with leaflet

How to get chrome logged in user's email id through website

using states in a react-navigation without redux